Page 1 of 1

php array manipulation - delete array

Posted: Thu Sep 22, 2011 3:58 pm
by ragan
In a function, I have this print_r($arrayValues ) giving output as
Array
(
[1] => Value1
)
Array
(
[1] => google
[2] => yahoo
[3] => hotmail
[4] => cnn
)
Array
(
[1] => bbc
[2] => nyt
[3] => msn
)

Now I want to delete the array that has the value "hotmail" and then just use the other array for my rest of the script. Not always the array are in this order so I cannot go with numbers like delete 2nd array, I can go only with the value because that value "hotmail" will always be there. There can be a question why I would even include this array in $arrayValues but I am helpless as these are generated by a function with data from mysql and I don't have control on that. I thought of unset but I don't know the array name, all I know is only a value which will be there always even if the other values in that array changes.

Please advise if there is a way to achieve this.

Re: php array manipulation - delete array

Posted: Thu Sep 22, 2011 5:02 pm
by AbraCadaver
Not tested but should work:

Code: Select all

if(($key = array_search('hotmail', $arrayValues)) !== false) {
   unset($arrayValues[$key]);
}