I have two arrays
$list = Array
([0] => stdClass Object
(
[id] => 10
[data] => "test data"
)
[1] => stdClass Object
...
...(max 3000 ~ 4000 items)
and
$attributes = Array
([0] => stdClass Object
(
[ids] => 11
[list] => '<ul>...</ul>'
)
[1] => stdClass Object
...
...(max 3000 ~ 4000 items)
I am trying to left join them but the only performing way I am being able to write for this to be usable is
$nrrowslist = count($list);
for ($i = 0; $i < $nrrowslist; $i++){
$nrat = count($attributes);
for ($j = 0; $j < $nrat; $j++)
{
if($list[$i]->id == $attributes[$j]->ids){
$list[$i]->attributes = $attributes[$j]->list;
array_splice($attributes, $j, 1); // remove the item
break; // since there is other item with that id
}
}
}
// completes in ~0.470 seconds
But if I write it
foreach($list as $art){
foreach($attributes as $attr){
if($art->id == $attr->ids){
$art->attributes = $attr->list;
}
}
}
it completes in ~ 5.500 seconds.. and is too much
what can I do to perform even more the first method situation?