<?php
$ar[0] = Array ( 'type' => 101, 'width' => 540, 'height' => 960, 'url' => 'https://a.com');
$ar[1] = Array ( 'type' => 102, 'width' => 340, 'height' => 604, 'url' => 'https://b.com');
$ar[2] = Array ( 'type' => 103, 'width' => 240, 'height' => 430, 'url' => 'https://c.com');
$ar[3] = Array ( 'type' => 104, 'width' => 240, 'height' => 420, 'url' => 'https://d.com');
$type = 102;
$indd = '';
foreach($ar as $ind=>$arr){
if ($arr['type'] == $type) {
$indd = $ind;
break;
}
}
if($indd){
echo $ar[$indd]['width'].PHP_EOL;
echo $ar[$indd]['height'].PHP_EOL;
echo $ar[$indd]['url'].PHP_EOL.PHP_EOL;
}
function arrayByType($arra, $type){
$indd = '';
foreach($arra as $ind=>$arr){
if ($arr['type'] == $type) {
$indd = $ind;
break;
}
}
if($indd){
return $arra[$indd];
}
}
print_r(arrayByType($ar, $type));
preferences:
25.26 ms | 404 KiB | 5 Q