extracting data from multidimensional array via PHP and store in text file -
i extract data following json arrays, variable use create text file
array ( [0] => array ( [0] => 0 [1] => ) [1] => array ( [0] => 0 [1] => 123: ) [2] => array ( [0] => 0 [1] => ticket ) [3] => array ( [0] => 0 [1] => ------------------------------------------------ ) [4] => array ( [0] => 1 [1] => user 1 ) [5] => array ( [0] => 1 [1] => info x ) [6] => array ( [0] => 0 [1] => ------------------------------------------------ ) [7] => array ( [0] => 0 [1] => text 1 ) [8] => array ( [0] => 0 [1] => text 2 ) [9] => array ( [0] => 0 [1] => text 4 ) [10] => array ( [0] => 1 [1] => text 4 ) [11] => array ( [0] => 0 [1] => text 5 ) [12] => array ( [0] => 0 [1] => text 6 ) [13] => array ( [0] => 0 [1] => text 7 ) [14] => array ( [0] => 0 [1] => text 8 ) [15] => array ( [0] => 0 [1] => text 9 ) )
i use following php, array 15 value returned in text file.
$ticket = file_get_contents('php://input'); $ticket_output = json_decode($ticket,true); $ticket_output_def = $ticket_output['ticket']; $ticket_output_txt = print_r($ticket_output_def,true); foreach ($ticket_output_def $array){ $array0 = $array[0]; $array1 = $array[1]; $text = $array0 . $array1; } $filename = "output.txt"; file_put_contents($filename, $text);
well that's normal since reset $text @ every loop iteration!
maybe try :
$ticket = file_get_contents('php://input'); $ticket_output = json_decode($ticket,true); $ticket_output_def = $ticket_output['ticket']; $ticket_output_txt = print_r($ticket_output_def,true); $text = ""; foreach ($ticket_output_def $array){ $array0 = $array[0]; $array1 = $array[1]; $text .= $array0 . $array1; } $filename = "output.txt"; file_put_contents($filename, $text);
Comments
Post a Comment