Page 1 of 1

unset array value

Posted: Wed Jun 14, 2006 7:39 am
by gurjit
hi,

how can i search through an array and unset a value

my array is for example:

Code: Select all

$enquiry_array = array ( 
1 => '222', 
2 => '223' 
3 => '224' 
);
i tried this code and it did not work

Code: Select all

<?php
if (in_array($eqid, $enquiry_array))
{  

   unset($enquiry_array[array_search($eqid, $enquiry_array)]); // $key = 0;
}
?>
I want to unset the value which will be passed through as $eqid

Posted: Wed Jun 14, 2006 8:33 am
by twigletmac
It worked for me using the following code:

Code: Select all

<?php

$enquiry_array = array (
	1 => '222',
	2 => '223',
	3 => '224'
);

$eqid = 223;

if (in_array($eqid, $enquiry_array)) { 
   unset($enquiry_array[array_search($eqid, $enquiry_array)]); // $key = 0;
}

echo '<pre>';
print_r($enquiry_array);
echo '</pre>';

?>
Are you sure that $eqid is being passed correctly?

Mac