Jump to content


Photo

Searching and deleting from an array???


  • Please log in to reply
3 replies to this topic

#1 eng_coo

eng_coo
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 17 September 2006 - 01:51 AM

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

#2 sasa

sasa
  • Staff Alumni
  • Advanced Member
  • 2,804 posts
  • LocationHrvatska

Posted 17 September 2006 - 06:19 AM

try
<?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);
?>


#3 eng_coo

eng_coo
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 17 September 2006 - 12:11 PM

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

#4 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 17 September 2006 - 12:20 PM

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.
<?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;
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users