Problems with array_push PHP 7.2

0

Greetings as they are all, I have a problem and I do not really know what happens, these are my versions:

Server version: Apache / 2.4.18 (Ubuntu)

PHP 7.2.11-4 + ubuntu16.04.1 + deb.sury.org + 1 (cli) (built: Nov 4 2018 05:10:57) (NTS)

I am making a query to my database and I want to organize that data in an array for what I am using array_push but it does not return any kind of response, I am forming the array in this way:

array_push($arr,array(
    "codarticulo"    => $row4["codarticulo"],
    "precio_venta"   => $row4["precio_venta"],
    "descripcion"    => $row4["descripcion"],
    "unidad_medida"  => $row4["unidad_medida"],
    "codfamilia"     => $row4["codfamilia"],
    "multiplo_venta" => $row4["multiplo_venta"]
  ));header('Content-Type: application/json');
  echo json_encode($arr);

The funny thing is that the production host works normally and in my development team, no one can tell me what is happening.

PS: the development team has the same versions as the production team

    
asked by Jeffry Jose Barrios Gomez 09.11.2018 в 16:15
source

1 answer

0

If the output you are getting is completely empty, most likely, the problem is with json_encode and not with array_push.

This function silently fails and returns FALSE which, when converted to string, becomes an empty string.

The most common problem is usually with the charset of the database, the table or the connection.

To be able to verify if this is the situation, it is better to do a print_r or var_dump of the array instead of an echo .

    
answered by 09.11.2018 в 16:57