A
A
AriSokol2016-10-23 17:51:53
PHP
AriSokol, 2016-10-23 17:51:53

How to display the elements of a multidimensional array without errors in php?

There is such a construction that displays 15 elements from an array (15 is the maximum in the array itself):
for ($i = 0; $i < 15; $i++) { echo ... }
but there is a problem - the array does not always contain 15 elements. There are 1 and 2 in total. then errors are poured into the browser :(
how to output all elements from the array without errors?
I tried this: it
for ($i = 0; $i < count($json); $i++){ echo ... }
displays only two elements :(
elements are dragged from here:

$Result = 'https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=15&type=video&q='.$search.'&key='.$youtube_key.;
$Result2 = file_get_contents($Result);
$json = json_decode($Result2);

elements are displayed in this form:
$element[$i]
made an array output - var_dump($json) :
object(stdClass)#1 (6) { ["kind"]=> string(26) "youtube#searchListResponse" ["etag"]=> string(57) ""I_8xdZu766_FSaexEaDXTIfEWc0/Wj2ZLGAfwqw4io35vUD2ESCm58U"" ["nextPageToken"]=> string(6) "CA8QAA" ["regionCode"]=> string(2) "RU" ["pageInfo"]=> object(stdClass)#2 (2) { ["totalResults"]=> int(1000000) ["resultsPerPage"]=> int(15) } ["items"]=> array(15) { [0]=> object(stdClass)#3 (4) { ["kind"]=> string(20) "youtube#searchResult" ["etag"]=> string(57) ""I_8xdZu766_FSaexEaDXTIfEWc0/Ae6ehuMAZpZWFRSMBSnvB6U4XZA"" ["id"]=> object(stdClass)#4 (2) { ["kind"]=> string(13) "youtube#video" ["videoId"]=> string(11) "he8nz5tAZrw" } ["snippet"]=> object(stdClass)#5 (7) { ["publishedAt"]=> string(24) "2016-03-29T05:17:40.000Z" ["channelId"]=> string(24) "UCfaZw8XH_zmAVkBst_MPD6w" ["title"]=> string(97) "Unboxing New Spiderman Battery-Powered Ride On Super Car 6V Test Drive Park Playtime Fun Ckn Toys" ["description"]=> string(160) "Hi guys today Spiderman will be unboxing and asemmbling this new super spiderman kids electric ride on 6 volt car.This would have to be our favourite car so ..." ["thumbnails"]=> object(stdClass)#6 (3) { ["default"]=> object(stdClass)#7 (3) { ["url"]=> string(46) "https://i.ytimg.com/vi/he8nz5tAZrw/default.jpg" ["width"]=> int(120) ["height"]=> int(90) } ["medium"]=> object(stdClass)#8 (3) { ["url"]=> string(48) "https://i.ytimg.com/vi/he8nz5tAZrw/mqdefault.jpg" ["width"]=> int(320) ["height"]=> int(180) } ["high"]=> object(stdClass)#9 (3) { ["url"]=> string(48) "https://i.ytimg.com/vi/he8nz5tAZrw/hqdefault.jpg" ["width"]=> int(480) ["height"]=> int(360) } } ["channelTitle"]=> string(8) "CKN Toys" ["liveBroadcastContent"]=> string(4) "none" } } [1]=> object(stdClass)#10 (4) { ["kind"]=> string(20) "youtube#searchResult" ["etag"]=> string(57) ...

and there are many such objects.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
S
Sergey, 2016-10-23
@VSeryoga

foreach($json as $element){
    echo $element;
}

L
lubezniy, 2016-12-12
@lubezniy

Check netstat to see if the port that RabbitMQ is trying to bind to is busy with something else.

A
aCL, 2016-12-12
@aCL

had the same thing, reinstall helped

F
FloeHetling, 2017-07-12
@FloeHetling

Increase the RAM on the server/virtual machine. Or temporarily unload it as much as possible.
Installing previous versions of erlang/rabbit from the deb packages may also help.
With my 1 GB of RAM, only a temporary increase to 2 GB helped. After a successful installation, I returned 1 gig. Works.

F
fred, 2019-09-02
@fred

Most likely, mnesia crashed, delete the contents of /var/lib/rabbitmq if the data that could remain in the queue is no longer relevant

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question