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
gurjit
Forum Contributor
Posts: 314 Joined: Thu May 15, 2003 11:53 am
Location: UK
Post
by gurjit » Wed Jun 14, 2006 7:39 am
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
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Wed Jun 14, 2006 8:33 am
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