Re: [PHP] Simple array question, array delete
Ryan A wrote: Hey, I have a $data_recs array like this: 12 445 45655 4 343 etc when the user gives me a number, i have to check if its in the array and delete that entry...how do i do that? I have looked at the manual but have gotten confused with array pop,splice,array_key_exists etc Thanks, Ryan The code follows : if (in_array($number, $data_recs)) { $key = array_search($number, $data_recs); // Get the key unset($data_recs[$key]); // Unset the variable } -- Josip Dzolonga http://josip.dotgeek.org jdzolonga[at]gmail.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Simple array question, array delete
On Apr 6, 2005 3:09 PM, Ryan A [EMAIL PROTECTED] wrote: Hey, I have a $data_recs array like this: 12 445 45655 4 343 etc when the user gives me a number, i have to check if its in the array and delete that entry...how do i do that? I have looked at the manual but have gotten confused with array pop,splice,array_key_exists etc Thanks, Ryan -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.308 / Virus Database: 266.9.3 - Release Date: 4/5/2005 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php foreach ($array as $key=$value) { if(strpos($value, $userValue) { unset($array['$key']); } } i believe... not sure if it works or not hope this helps
Re: [PHP] Simple array question, array delete
On Apr 6, 2005 3:27 PM, Ken [EMAIL PROTECTED] wrote: On Apr 6, 2005 3:09 PM, Ryan A [EMAIL PROTECTED] wrote: Hey, I have a $data_recs array like this: 12 445 45655 4 343 etc when the user gives me a number, i have to check if its in the array and delete that entry...how do i do that? I have looked at the manual but have gotten confused with array pop,splice,array_key_exists etc Thanks, Ryan -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.308 / Virus Database: 266.9.3 - Release Date: 4/5/2005 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php foreach ($array as $key=$value) { if(strpos($value, $userValue) { unset($array['$key']); } } i believe... not sure if it works or not hope this helps sorry the if bit is not strpos if ($value == $userValue) { // the unset part here }
Re: [PHP] Simple array question, array delete
On Wed, April 6, 2005 6:09 am, Ryan A said: when the user gives me a number, i have to check if its in the array and delete that entry...how do i do that? I have looked at the manual but have gotten confused with array pop,splice,array_key_exists etc http://php.net/array_search http://php.net/unset It can be confusing at first, with all the different functions that all seem to do not quite what you want. :-) -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Simple array question, array delete
On 4/7/2005 5:19:24 AM, [EMAIL PROTECTED] wrote: On Wed, April 6, 2005 6:09 am, Ryan A said: when the user gives me a number, i have to check if its in the array and delete that entry...how do i do that? I have looked at the manual but have gotten confused with array pop,splice,array_key_exists etc http://php.net/array_search http://php.net/unset It can be confusing at first, with all the different functions that all seem to do not quite what you want. :-) Exactly...theres a s**tload of array functions there...and php being so robust I figured there would be one simple function instead of combining two I have unsed unset in the past...but not array_search Thanks, Ryan -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.308 / Virus Database: 266.9.4 - Release Date: 4/6/2005 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php