php array manipulation - delete array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ragan
Forum Newbie
Posts: 1
Joined: Thu Sep 22, 2011 3:30 pm

php array manipulation - delete array

Post 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.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: php array manipulation - delete array

Post by AbraCadaver »

Not tested but should work:

Code: Select all

if(($key = array_search('hotmail', $arrayValues)) !== false) {
   unset($arrayValues[$key]);
}
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply