Попробуй дальше. У меня это работает:
<code> $i = 0; // counter
$ar = []; // array of indexes of success objects
$ar2 = []; // result array of objects which title has 'Laravel' inside
// $obj_ar must be consists of objects (it should has some checking code for that requirement)
// filling an array of indexes $ar
foreach ($obj_ar as $obj_1){
if (strstr($obj_1->title,'Laravel')) array_push ($ar, $i);
$i++;
}
// building a result array of objects
$count_ar = count($ar);
if ($count_ar>0) {
for($o = 0; $o < $count_ar; $o++){
array_push ($ar2, $obj_ar[$o]);
}
}
// result array of objects
echo '<pre>';
print_r($ar2);
echo '
';
или чуть более быстрый путь:
<code> $i = 0; // counter
$ar2 = []; // result array of objects which title has 'Laravel' inside
// $obj_ar must be consists of objects (it should has some checking code for that requirement)
// filling an array of indexes $ar
foreach ($obj_ar as $obj_1){
if (strstr($obj_1->title,'Laravel')) array_push ($ar2, $obj_ar[$i]);
$i++;
}
// result array of objects
echo '<pre>';
print_r($ar2);
echo '
';