array questions.

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

Post Reply
lizlazloz
Forum Commoner
Posts: 64
Joined: Mon Dec 29, 2003 7:29 am

array questions.

Post by lizlazloz »

ok, first this sounds really noobish, but say i have an array, and i want to find if any of the elements in the array have a specified value, how would i do that?

secondly, how would i remove an element from an array?
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

Code: Select all

for($i=0; $i<count($myarray); $i++)
{
   if ($myarray[$i] = 'some value')
   {
        // Do something
   }
}
in place of Do something, you could redefine that array to be something else

$myarray[$i] = 'this string';

hope this helps.
Post Reply