Jump to content

Archived

This topic is now archived and is closed to further replies.

eng_coo

Searching and deleting from an array???

Recommended Posts

Hi,

i know its possible to delete first and last values from an array but is it possible to delete a specific value from an array (possibly a user search to delete a certain value)???

cheers
john

Share this post


Link to post
Share on other sites
try[code]<?php
$a=array('sasa','qwe','poi');
print_r($a);
$remowe = 'qwe';
echo "\n<hr /> Remove element $remowe\n\n";
unset($a[array_search($remowe,$a)]);
print_r($a);
?>[/code]

Share this post


Link to post
Share on other sites
Hi,

thanks thats great just what i wanted. But as i am new to php could you explain what the line -

unset($a[array_search($remowe,$a)]);

means. i know it searches the array for the value but, i have never come across 'unset' before. is it basically just delete from varible $a and can it only be used with arrays?

thanks

john

Share this post


Link to post
Share on other sites
unset is to unset() a varable

when you use the code below your only see one echoed redarrow
as the seconed ecohed redarrow is unset.

good luck.
[code]
<?php
// name is redarrow
$name="redarrow";
/// echo the name redaarow
echo $name;
//unset varable $name what was redarrow
unset($name);
// echo name now nothink why becouse we unset the varable........
echo $name;
?>
[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.