Jump to content

[SOLVED] search array in an array


AV1611

Recommended Posts

OK

I think I'm on the right track, but I have one more question:

[code]
$s=0
$str=array();
while($s<=26)
{$str[]="player_".$s;}
foreach ($str AS $item) {
if (in_array($item, $data)) {
        // I want to echo the current array item from $data
        }
}
[/code]
PS Having created the $str array you can find which are in the $data array with

http://www.php.net/array_intersect

[code]
<?php

$str = array ('a', 'b', 'c', 'd', 'e');
$data = array ('a', 'd', 'g');

$result = array_intersect($data, $str);

echo '<pre>', print_r($result, true), '</pre>';
?>
[/code]

-->
[pre]
[nobbc]
Array
(
    [0] => a
    [1] => d
)
[/nobbc]
[/pre]

Archived

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

×
×
  • 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.