简体   繁体   中英

I can not access the array in PHP

I'm sending an array from javascript to PHP file. When doing echo $newArray inside the .php file, it shows me the array correctly:

array(4) { ["titulo"]=> string(28) "Curso de canvas y Javascript ["cantidad"]=> string(1) "1" ["valorItem"]=> string(2) "10"["idProducto"]=> string(3) "403" }
array(4) { ["titulo"]=> string(15) "Curso de jQuery" ["cantidad"]=> string(1) "1" ["valorItem"]=> string(2) "10"["idProducto"]=> string(3) "402" }

How do I access some element of the array? I have tried with this:

$newArray = $_POST["array"];

$title = json_decode($newArray[0]["titulo"]);

echo $title;

But this appears:

Warning: Illegal string offset 'titulo' in C:\\xampp\\htdocs\\frontend\\controladores\\carrito.controlador.php on line 78

I tried everything that says in other questions of this type in the stack, but it has not worked

where is your javascript? You can do something like

$title = $_POST['titulo'] 

similarly do other things

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM