|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2015-11-04 18:09 UTC] requinix@php.net
-Status: Open
+Status: Feedback
[2015-11-04 18:09 UTC] requinix@php.net
[2015-11-05 08:27 UTC] zjoclips at gmail dot com
[2015-11-05 09:17 UTC] requinix@php.net
[2015-11-15 04:22 UTC] php-bugs at lists dot php dot net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Dec 16 22:00:01 2025 UTC |
Description: ------------ When you use the variable $row in an for iteration or foreach the last element ech time become the current element and at end of iteration become empty. I think is an issue about the name of variable but nobody knows that, maybe you can introduce a warning in the documentation or resolve this problem Test script: --------------- $jsonString = '{"head":["Vehicle Name","2015-10-05","2015-10-06","2015-10-07","2015-10-08","2015-10-09","2015-10-13","2015-10-15","2015-10-16","2015-10-17","2015-10-18","2015-10-19"],"body":[[["V CLASS","1"],["40","","6","2015-10-05"],["41","prova2_2 prova2_2","2","2015-10-06"],["64","","2","2015-10-07"],["65","","2","2015-10-08"],["66","","2","2015-10-09"],["69","","2","2015-10-13"],["35","","6","2015-10-15"],["36","","6","2015-10-16"],["37","","6","2015-10-17"],["38","","6","2015-10-18"],["39","","6","2015-10-19"]],[["CARAVELLE[AB123CD]","2"],["","","","2015-10-05"],["","","","2015-10-06"],["","","","2015-10-07"],["","","","2015-10-08"],["","","","2015-10-09"],["","","","2015-10-13"],["4","Driver_6 Driver_6","8","2015-10-15"],["","","","2015-10-16"],["","","","2015-10-17"],["","","","2015-10-18"],["","","","2015-10-19"]],[["MAGELYS","5"],["42","driverFront office","54","2015-10-05"],["","","","2015-10-06"],["","","","2015-10-07"],["","","","2015-10-08"],["","","","2015-10-09"],["","","","2015-10-13"],["","","","2015-10-15"],["","","","2015-10-16"],["","","","2015-10-17"],["","","","2015-10-18"],["","","","2015-10-19"]],[["NN","12"],["70","Autista 2 driver 2.0","25","2015-10-05"],["","","","2015-10-06"],["71","","6","2015-10-07"],["","","","2015-10-08"],["","","","2015-10-09"],["","","","2015-10-13"],["49","prova_3 prova_3","25","2015-10-15"],["","","","2015-10-16"],["48","","25","2015-10-17"],["","","","2015-10-18"],["","","","2015-10-19"]],[["NN","16"],["50","prova asdasd","25","2015-10-05"],["","","","2015-10-06"],["","","","2015-10-07"],["","","","2015-10-08"],["","","","2015-10-09"],["","","","2015-10-13"],["","","","2015-10-15"],["","","","2015-10-16"],["","","","2015-10-17"],["","","","2015-10-18"],["","","","2015-10-19"]],[["E CLASS","17"],["","","","2015-10-05"],["","","","2015-10-06"],["","","","2015-10-07"],["","","","2015-10-08"],["","","","2015-10-09"],["55","","2","2015-10-13"],["57","","2","2015-10-15"],["58","","2","2015-10-16"],["59","","2","2015-10-17"],["60","","2","2015-10-18"],["61","","2","2015-10-19"]],[["E CLASS","19"],["","","","2015-10-05"],["51","","3","2015-10-06"],["52","","3","2015-10-07"],["53","","3","2015-10-08"],["54","","3","2015-10-09"],["","","","2015-10-13"],["","","","2015-10-15"],["","","","2015-10-16"],["","","","2015-10-17"],["","","","2015-10-18"],["","","","2015-10-19"]],[["V CLASS","25"],["","","","2015-10-05"],["","","","2015-10-06"],["","","","2015-10-07"],["","","","2015-10-08"],["","","","2015-10-09"],["","","","2015-10-13"],["","","","2015-10-15"],["","","","2015-10-16"],["","","","2015-10-17"],["","","","2015-10-18"],["","","","2015-10-19"]],[["S CLASS","30"],["","","","2015-10-05"],["","","","2015-10-06"],["","","","2015-10-07"],["","","","2015-10-08"],["","","","2015-10-09"],["","","","2015-10-13"],["","","","2015-10-15"],["","","","2015-10-16"],["","","","2015-10-17"],["","","","2015-10-18"],["","","","2015-10-19"]],[["VIANO","31"],["","","","2015-10-05"],["","","","2015-10-06"],["","","","2015-10-07"],["","","","2015-10-08"],["","","","2015-10-09"],["","","","2015-10-13"],["","","","2015-10-15"],["","","","2015-10-16"],["","","","2015-10-17"],["","","","2015-10-18"],["","","","2015-10-19"]],[["S CLASS","33"],["","","","2015-10-05"],["","","","2015-10-06"],["","","","2015-10-07"],["","","","2015-10-08"],["","","","2015-10-09"],["","","","2015-10-13"],["","","","2015-10-15"],["","","","2015-10-16"],["","","","2015-10-17"],["","","","2015-10-18"],["","","","2015-10-19"]],[["SPRINTER","34"],["","","","2015-10-05"],["","","","2015-10-06"],["","","","2015-10-07"],["","","","2015-10-08"],["","","","2015-10-09"],["","","","2015-10-13"],["","","","2015-10-15"],["","","","2015-10-16"],["","","","2015-10-17"],["","","","2015-10-18"],["","","","2015-10-19"]],[["prova_1","35"],["","","","2015-10-05"],["","","","2015-10-06"],["","","","2015-10-07"],["","","","2015-10-08"],["","","","2015-10-09"],["","","","2015-10-13"],["","","","2015-10-15"],["","","","2015-10-16"],["","","","2015-10-17"],["","","","2015-10-18"],["","","","2015-10-19"]],[["S CLASS","37"],["","","","2015-10-05"],["","","","2015-10-06"],["","","","2015-10-07"],["","","","2015-10-08"],["","","","2015-10-09"],["","","","2015-10-13"],["","","","2015-10-15"],["","","","2015-10-16"],["","","","2015-10-17"],["","","","2015-10-18"],["","","","2015-10-19"]],[["CARAVELLE","38"],["","","","2015-10-05"],["","","","2015-10-06"],["","","","2015-10-07"],["","","","2015-10-08"],["","","","2015-10-09"],["","","","2015-10-13"],["","","","2015-10-15"],["","","","2015-10-16"],["","","","2015-10-17"],["","","","2015-10-18"],["","","","2015-10-19"]]],"total":"15"}'; $json = json_decode($jsonString, true); for($i = 0; $i < count($json["body"]); $i ++){ $row = $json["body"][$i]; echo "$i -> ".$row[0][0]." | ".$json["body"][count($json["body"])-1][0][0]."\n"; } Expected result: ---------------- 0 -> V CLASS | CARAVELLE 1 -> CARAVELLE[AB123CD] | CARAVELLE 2 -> MAGELYS | CARAVELLE 3 -> NN | CARAVELLE 4 -> NN | CARAVELLE 5 -> E CLASS | CARAVELLE 6 -> E CLASS | CARAVELLE 7 -> V CLASS | CARAVELLE 8 -> S CLASS | CARAVELLE 9 -> VIANO | CARAVELLE 10 -> S CLASS | CARAVELLE 11 -> SPRINTER | CARAVELLE 12 -> prova_1 | CARAVELLE 13 -> S CLASS | CARAVELLE 14 -> CARAVELLE | CARAVELLE Actual result: -------------- 0 -> V CLASS | V CLASS 1 -> CARAVELLE[AB123CD] | CARAVELLE[AB123CD] 2 -> MAGELYS | MAGELYS 3 -> NN | NN 4 -> NN | NN 5 -> E CLASS | E CLASS 6 -> E CLASS | E CLASS 7 -> V CLASS | V CLASS 8 -> S CLASS | S CLASS 9 -> VIANO | VIANO 10 -> S CLASS | S CLASS 11 -> SPRINTER | SPRINTER 12 -> prova_1 | prova_1 13 -> S CLASS | S CLASS 14 -> S CLASS | S CLASS