Why do; Warning array_push() expects Parameter 1 to be array, integer Given in /var/www/html/serie/editor_temporada/Make.php on line 83?

Asked

Viewed 778 times

0

Can someone help me?

Why this passage array_push($valorDeLinks[$i], $getValueLinks); Return me a Warning?

array_push() expects Parameter 1 to be array, integer Given in /var/www/html/serie/editor_temporada/Make.php on line 83

63    //Obtendo valor de links-----------------------------------------------
64    $valorDeLinks = array();
65    $urlDeLinks = array();
66    
67    for ($i = 0; $i < $nomeDasTabelas['value']; $i ++) {
68        $getValueLinks = 0;
69    
70        $obtendo = mysqli_query($conect, "SELECT * FROM $nomeDasTabelas[$i]");
71        if ($obtendo != true) {
72            $log = $log . "<script>console.log('Falha ao consultar a DATABASE -Obtendo tabelas da serie-)</script>";
73        } else {
74            $urlDeLinks[$i] = array();
75            $valorDeLinks[$i] = 0;
76            
77            while ($dados = $obtendo->fetch_array()) {
78                
79                array_push($urlDeLinks[$i], $dados['link']);
80                $getValueLinks ++;
81            }
82            var_dump($valorDeLinks[$i]);
83            array_push($valorDeLinks[$i], $getValueLinks);
84        }
85    }
86    print_r($urlDeLinks); //OK
87    print_r($valorDeLinks); //array_push() expects parameter 1 to be array, integer given in /var/www/html/serie/editor_temporada/Make.php on line
  • 1

    Why the $i here $urlDeLinks[$i]? It should just be array_push($urlDeLinks, $dados['link']);

  • Believe me, I’ve mistaken it for an array. So I don’t need to initialize it with $valorDeLinks[$i] = 0; ?

  • 1

    You’re already initializing with $urlDeLinks = array();, unless you want arrays inside arrays.

  • Thank you very much!!

  • Worked the way you wanted?

1 answer

0


You don’t need to put the index when using the function array_push. Just say which variable your array:

array_push($valorDeLinks, $getValueLinks);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.