Jump to content

eng_coo

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

eng_coo's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Cheers both of you, both ways worked a charm cheers john
  2. Hi, I search single dimensional arrays using in_array() function. However i have got a multidimensional array containing users. At the moment i am looping through each array to see if the person exists but as more users get added the code would be very large. Is there an easier way to search a multidimensional array. Here is my code the array has just 2 users in it at moment - [code] $people = array (array ("idx"=>"1", UserName=>"John", Password=>"me", FirstName =>"John"),           array ("idx"=>"2", UserName =>"Pete", Password=>"pete", FirstName =>"Pete")); print_r($people); $user ="John"; if (in_array($user,$people[0])) { echo "john exists in array 1"; } else { if (in_array($user,$people[1])) { echo "john exists in array 2"; } else { echo "program not worked!!"; }} echo "<br><br>"; [/code] As you can see it searchs each of the internal arrays (0,1). So I i had 60 users it would need 60 loops. There must be a more effective way of searching through an entire mulitdimensional array in one loop as in_array($user, $people) doesnt work as $people shows up as 0=>Array 1=>Array Any help much appreciated cheers John
  3. 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. 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
  5. hi, im pretty new to php but need to learn it for a big project. At the moment i have a page which displays a form. the user clicks on the item(s) they want and then it displays the item(s) that they clicked from an array. However i want to store what they select so that when  select another item from the checkboxes it just sticks the value on the end of the previous ones (at the moment it seems to overwrite wats already in there) is this possible? heres my code - <form action = "<?php echo $_SERVER['PHP_SELF']; ?>" form method = "POST"> <h5> Pick which phones you like - </h5> <input type = "checkbox" name = "phones[]" value="nokia"/> Nokia <br /> <input type = "checkbox" name = "phones[]" value="sony" /> Sony Erricsson <br /> <input type = "checkbox" name = "phones[]" value="motorola" /> Motorola <br /> <input type = "checkbox" name = "phones[]" value="seimens" /> seimens <br /> <input type = "checkbox" name = "phones[]" value="poo" /> Poo <br /> <input type = "submit" name = "pressed" value = "Select"> <br><br> <? if (isset($_POST['pressed'])) { echo"You have seleted the following phones :"; echo"<br>"; foreach($_POST['phones'] as $phone) array_push($yours, $phone);  echo "$phone<br />"; } print_r($yours); As you can see i loop through the array and use array_push to add the values selected onto the end of $yours array. however when u select some more phones it overwrites the ones in the $yours array and i want it to add them to the end. im probably going bout it the wrong way. any help greatly appreciated cheers john
×
×
  • Create New...

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.