foreach($json->object->attachments[0]->photo->sizes as $photo) {
if($photo->type == "w") {
$photo_original = $photo->type;
} elseif($photo->type == "z") {
$photo_original = $photo->type;
} elseif($photo->type == "y") {
$photo_original = $photo->type;
} elseif($photo->type == "r") {
$photo_original = $photo->type;
} elseif($photo->type == "q") {
$photo_original = $photo->type;
} elseif($photo->type == "p") {
$photo_original = $photo->type;
} elseif($photo->type == "o") {
$photo_original = $photo->type;
} elseif($photo->type == "x") {
$photo_original = $photo->type;
} elseif($photo->type == "m") {
$photo_original = $photo->type;
} elseif($photo->type == "s") {
$photo_original = $photo->type;
}
$json_attach = array(
'type' => 'link',
'url' => $photo_original
);
}
<?php
foreach($json->object->attachments[0]->photo->sizes as $photo) {
foreach(["w", "z", "y", "r", "q", "p", "o", "x", "m", "s"] as $type) {
if($photo->type == $type) {
$json_attach = [
'type' => 'link',
'url' => $photo->url,
'photo_type' => $photo->type,
];
break(2); //прерываем дальнейший поиск
}
}
}
print_r($json_attach);