10:23 pm
August 26, 2013
12:40 pm
August 26, 2013
8:14 pm
July 26, 2011
Sorry to reopen an old thread, but for whatever reason I've been unable to unset an array element using this method. array_diff seems to work just fine, though.
unset($post['categories']['r']);
vs
$post['categories'] = array_diff($post['categories'], ["r"]);
Any idea one works, but the other doesn't?
Thanks!
Because there is no 'r' element in your $post['categories'] array. Most likely you have something like this:
$post['categories'][5] = 'r';
or this
$post['categories'][0] = 'r';
To remove the $post['categories'] element, you have to specify its numerical id, but not its value. E.g.:
unset($post['categories'][3]);
7:58 am
July 26, 2011
I guess I'm a little confused. How do I unset category by name? I tried the snippet you supplied. I understand how unset works and have used it with other arrays. If I have a category called "dogs" that I want to unset, wouldn't I just use this?
unset($post['categories']['dogs']);
I'm looking to unset by value, not element number.
Thanks!
Most Users Ever Online: 541
Currently Online:
20 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
ninja321: 84
s.baryshev.aoasp: 68
Freedom: 61
Pandermos: 54
MediFormatica: 49
B8europe: 48
Member Stats:
Guest Posters: 337
Members: 2817
Moderators: 0
Admins: 1
Forum Stats:
Groups: 1
Forums: 5
Topics: 1627
Posts: 8280
Newest Members:
igor.buzaev, jeremyboucher, lthompson2709, MAC, duty3canada, backlinkmoroccoAdministrators: CyberSEO: 3913