3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $cols = Array ( 0 => 'Name', 1 => 'MCR', 2 => 'MCD', 3 => 'COM', 4 => 'INV', 5 => 'IDM', 6 => 'PPO', 7 => 'HKD', 8 => 'ALL', 9 => 'POS', 10 => 'MCD-SP', 11 => 'MCD-BH', 12 => 'MCD-CL', 13 => 'MCD-CO', 14 => 'MCR-SP', 15 => 'MCR-PO' ); $rows = Array( 0 => Array( 0 => 'Primero', 1 => 19683.43, 2 => NULL, 3 => 3757.38, 4 => NULL, 5 => NULL, 6 => NULL, 7 => NULL, 8 => NULL, 9 => NULL, 10 => NULL, 11 => NULL, 12 => NULL, 13 => NULL, 14 => NULL, 15 => NULL ), 1 => Array ( 0 => 'Segundo', 1 => 15340.5767, 2 => NULL, 3 => NULL, 4 => NULL, 5 => NULL, 6 => NULL, 7 => NULL, 8 => NULL, 9 => NULL, 10 => NULL, 11 => NULL, 12 => NULL, 13 => NULL, 14 => NULL, 15 => NULL ), 2 => Array ( 0 => 'Tercero', 1 => NULL, 2 => NULL, 3 => NULL, 4 => NULL, 5 => NULL, 6 => NULL, 7 => NULL, 8 => NULL, 9 => NULL, 10 => 4969.65, 11 => NULL, 12 => NULL, 13 => NULL, 14 => 23695.39, 15 => NULL ), 3 => Array ( 0 => 'Cuarto', 1 => NULL, 2 => NULL, 3 => NULL, 4 => NULL, 5 => NULL, 6 => NULL, 7 => NULL, 8 => NULL, 9 => NULL, 10 => NULL, 11 => 45974.86, 12 => NULL, 13 => NULL, 14 => NULL, 15 => NULL ), 4 => Array ( 0 => 'Quinto', 1 => NULL, 2 => NULL, 3 => NULL, 4 => NULL, 5 => NULL, 6 => NULL, 7 => NULL, 8 => NULL, 9 => NULL, 10 => 1405.8, 11 => 39244, 12 => NULL, 13 => NULL, 14 => NULL, 15 => NULL ) ); $qty_col = count($cols) - 1; $qty_rows = count($rows); //echo $qty_rows; $ifScript = ''; for ($a = 1; $a <= $qty_col; $a++) { $unsetScript = 'unset('; $ifScript .='if('; for ($b = 0; $b <= $qty_rows; $b++) { $ifScript .= 'empty($rows[' . $b . '][' . $a . '])'; $unsetScript .='$rows[' . $b . '][' . $a . ']'; if ($b == $qty_rows) { $ifScript .='){'; //$ifScript .='){<br>'; $unsetScript .=', $cols[' . $a . ']);'; } else { $ifScript .= ' && '; $unsetScript .=', '; } } $ifScript .= $unsetScript . '}'; //$ifScript .= $unsetScript . '<br>}<br>'; } //echo $ifScript; eval($ifScript); $cols = array_values($cols); $rows = array_map('array_values', $rows); foreach ($cols as $key => $value) { $cols[$key] = array( 'id' => NULL, 'label' => $value ); $type = ($key == 0) ? 'string' : 'number'; $cols[$key]['type'] = $type; } foreach ($rows as $key1 => $value1) { foreach ($value1 as $key2 => $value2) { $val = (empty($value2)) ? '0.00' : $value2; $format = ($key2 == 0) ? strtoupper(trim($value2)) : '$' . number_format($value2, '2', '.', ','); $value1[$key2] = array( 'v' => $val, 'f' => $format ); } $rows[$key1] = array( 'c' => $value1 ); } $newArray = array( 'cols' => $cols, 'rows' => $rows ); echo '<pre>'; print_r($newArray); echo '</pre>';
Output for 5.0.0 - 5.6.25, hhvm-3.10.0, 7.0.0 - 7.1.0
<pre>Array ( [cols] => Array ( [0] => Array ( [id] => [label] => Name [type] => string ) [1] => Array ( [id] => [label] => MCR [type] => number ) [2] => Array ( [id] => [label] => COM [type] => number ) [3] => Array ( [id] => [label] => MCD-SP [type] => number ) [4] => Array ( [id] => [label] => MCD-BH [type] => number ) [5] => Array ( [id] => [label] => MCR-SP [type] => number ) ) [rows] => Array ( [0] => Array ( [c] => Array ( [0] => Array ( [v] => Primero [f] => PRIMERO ) [1] => Array ( [v] => 19683.43 [f] => $19,683.43 ) [2] => Array ( [v] => 3757.38 [f] => $3,757.38 ) [3] => Array ( [v] => 0.00 [f] => $0.00 ) [4] => Array ( [v] => 0.00 [f] => $0.00 ) [5] => Array ( [v] => 0.00 [f] => $0.00 ) ) ) [1] => Array ( [c] => Array ( [0] => Array ( [v] => Segundo [f] => SEGUNDO ) [1] => Array ( [v] => 15340.5767 [f] => $15,340.58 ) [2] => Array ( [v] => 0.00 [f] => $0.00 ) [3] => Array ( [v] => 0.00 [f] => $0.00 ) [4] => Array ( [v] => 0.00 [f] => $0.00 ) [5] => Array ( [v] => 0.00 [f] => $0.00 ) ) ) [2] => Array ( [c] => Array ( [0] => Array ( [v] => Tercero [f] => TERCERO ) [1] => Array ( [v] => 0.00 [f] => $0.00 ) [2] => Array ( [v] => 0.00 [f] => $0.00 ) [3] => Array ( [v] => 4969.65 [f] => $4,969.65 ) [4] => Array ( [v] => 0.00 [f] => $0.00 ) [5] => Array ( [v] => 23695.39 [f] => $23,695.39 ) ) ) [3] => Array ( [c] => Array ( [0] => Array ( [v] => Cuarto [f] => CUARTO ) [1] => Array ( [v] => 0.00 [f] => $0.00 ) [2] => Array ( [v] => 0.00 [f] => $0.00 ) [3] => Array ( [v] => 0.00 [f] => $0.00 ) [4] => Array ( [v] => 45974.86 [f] => $45,974.86 ) [5] => Array ( [v] => 0.00 [f] => $0.00 ) ) ) [4] => Array ( [c] => Array ( [0] => Array ( [v] => Quinto [f] => QUINTO ) [1] => Array ( [v] => 0.00 [f] => $0.00 ) [2] => Array ( [v] => 0.00 [f] => $0.00 ) [3] => Array ( [v] => 1405.8 [f] => $1,405.80 ) [4] => Array ( [v] => 39244 [f] => $39,244.00 ) [5] => Array ( [v] => 0.00 [f] => $0.00 ) ) ) ) ) </pre>
Output for hhvm-3.12.0
Warning: number_format() expects parameter 1 to be double, null given in /in/IlDj2 on line 161 Warning: number_format() expects parameter 1 to be double, null given in /in/IlDj2 on line 161 Warning: number_format() expects parameter 1 to be double, null given in /in/IlDj2 on line 161 Warning: number_format() expects parameter 1 to be double, null given in /in/IlDj2 on line 161 Warning: number_format() expects parameter 1 to be double, null given in /in/IlDj2 on line 161 Warning: number_format() expects parameter 1 to be double, null given in /in/IlDj2 on line 161 Warning: number_format() expects parameter 1 to be double, null given in /in/IlDj2 on line 161 Warning: number_format() expects parameter 1 to be double, null given in /in/IlDj2 on line 161 Warning: number_format() expects parameter 1 to be double, null given in /in/IlDj2 on line 161 Warning: number_format() expects parameter 1 to be double, null given in /in/IlDj2 on line 161 Warning: number_format() expects parameter 1 to be double, null given in /in/IlDj2 on line 161 Warning: number_format() expects parameter 1 to be double, null given in /in/IlDj2 on line 161 Warning: number_format() expects parameter 1 to be double, null given in /in/IlDj2 on line 161 Warning: number_format() expects parameter 1 to be double, null given in /in/IlDj2 on line 161 Warning: number_format() expects parameter 1 to be double, null given in /in/IlDj2 on line 161 Warning: number_format() expects parameter 1 to be double, null given in /in/IlDj2 on line 161 <pre>Array ( [cols] => Array ( [0] => Array ( [id] => [label] => Name [type] => string ) [1] => Array ( [id] => [label] => MCR [type] => number ) [2] => Array ( [id] => [label] => COM [type] => number ) [3] => Array ( [id] => [label] => MCD-SP [type] => number ) [4] => Array ( [id] => [label] => MCD-BH [type] => number ) [5] => Array ( [id] => [label] => MCR-SP [type] => number ) ) [rows] => Array ( [0] => Array ( [c] => Array ( [0] => Array ( [v] => Primero [f] => PRIMERO ) [1] => Array ( [v] => 19683.43 [f] => $19,683.43 ) [2] => Array ( [v] => 3757.38 [f] => $3,757.38 ) [3] => Array ( [v] => 0.00 [f] => $ ) [4] => Array ( [v] => 0.00 [f] => $ ) [5] => Array ( [v] => 0.00 [f] => $ ) ) ) [1] => Array ( [c] => Array ( [0] => Array ( [v] => Segundo [f] => SEGUNDO ) [1] => Array ( [v] => 15340.5767 [f] => $15,340.58 ) [2] => Array ( [v] => 0.00 [f] => $ ) [3] => Array ( [v] => 0.00 [f] => $ ) [4] => Array ( [v] => 0.00 [f] => $ ) [5] => Array ( [v] => 0.00 [f] => $ ) ) ) [2] => Array ( [c] => Array ( [0] => Array ( [v] => Tercero [f] => TERCERO ) [1] => Array ( [v] => 0.00 [f] => $ ) [2] => Array ( [v] => 0.00 [f] => $ ) [3] => Array ( [v] => 4969.65 [f] => $4,969.65 ) [4] => Array ( [v] => 0.00 [f] => $ ) [5] => Array ( [v] => 23695.39 [f] => $23,695.39 ) ) ) [3] => Array ( [c] => Array ( [0] => Array ( [v] => Cuarto [f] => CUARTO ) [1] => Array ( [v] => 0.00 [f] => $ ) [2] => Array ( [v] => 0.00 [f] => $ ) [3] => Array ( [v] => 0.00 [f] => $ ) [4] => Array ( [v] => 45974.86 [f] => $45,974.86 ) [5] => Array ( [v] => 0.00 [f] => $ ) ) ) [4] => Array ( [c] => Array ( [0] => Array ( [v] => Quinto [f] => QUINTO ) [1] => Array ( [v] => 0.00 [f] => $ ) [2] => Array ( [v] => 0.00 [f] => $ ) [3] => Array ( [v] => 1405.8 [f] => $1,405.80 ) [4] => Array ( [v] => 39244 [f] => $39,244.00 ) [5] => Array ( [v] => 0.00 [f] => $ ) ) ) ) ) </pre>
Output for 4.3.0 - 4.4.9
Notice: Undefined offset: 5 in /in/IlDj2(145) : eval()'d code on line 1 Notice: Undefined offset: 5 in /in/IlDj2(145) : eval()'d code on line 1 Notice: Undefined offset: 5 in /in/IlDj2(145) : eval()'d code on line 1 Notice: Undefined offset: 5 in /in/IlDj2(145) : eval()'d code on line 1 Notice: Undefined offset: 5 in /in/IlDj2(145) : eval()'d code on line 1 Notice: Undefined offset: 5 in /in/IlDj2(145) : eval()'d code on line 1 Notice: Undefined offset: 5 in /in/IlDj2(145) : eval()'d code on line 1 Notice: Undefined offset: 5 in /in/IlDj2(145) : eval()'d code on line 1 Notice: Undefined offset: 5 in /in/IlDj2(145) : eval()'d code on line 1 Notice: Undefined offset: 5 in /in/IlDj2(145) : eval()'d code on line 1 <pre>Array ( [cols] => Array ( [0] => Array ( [id] => [label] => Name [type] => string ) [1] => Array ( [id] => [label] => MCR [type] => number ) [2] => Array ( [id] => [label] => COM [type] => number ) [3] => Array ( [id] => [label] => MCD-SP [type] => number ) [4] => Array ( [id] => [label] => MCD-BH [type] => number ) [5] => Array ( [id] => [label] => MCR-SP [type] => number ) ) [rows] => Array ( [0] => Array ( [c] => Array ( [0] => Array ( [v] => Primero [f] => PRIMERO ) [1] => Array ( [v] => 19683.43 [f] => $19,683.43 ) [2] => Array ( [v] => 3757.38 [f] => $3,757.38 ) [3] => Array ( [v] => 0.00 [f] => $0.00 ) [4] => Array ( [v] => 0.00 [f] => $0.00 ) [5] => Array ( [v] => 0.00 [f] => $0.00 ) ) ) [1] => Array ( [c] => Array ( [0] => Array ( [v] => Segundo [f] => SEGUNDO ) [1] => Array ( [v] => 15340.5767 [f] => $15,340.58 ) [2] => Array ( [v] => 0.00 [f] => $0.00 ) [3] => Array ( [v] => 0.00 [f] => $0.00 ) [4] => Array ( [v] => 0.00 [f] => $0.00 ) [5] => Array ( [v] => 0.00 [f] => $0.00 ) ) ) [2] => Array ( [c] => Array ( [0] => Array ( [v] => Tercero [f] => TERCERO ) [1] => Array ( [v] => 0.00 [f] => $0.00 ) [2] => Array ( [v] => 0.00 [f] => $0.00 ) [3] => Array ( [v] => 4969.65 [f] => $4,969.65 ) [4] => Array ( [v] => 0.00 [f] => $0.00 ) [5] => Array ( [v] => 23695.39 [f] => $23,695.39 ) ) ) [3] => Array ( [c] => Array ( [0] => Array ( [v] => Cuarto [f] => CUARTO ) [1] => Array ( [v] => 0.00 [f] => $0.00 ) [2] => Array ( [v] => 0.00 [f] => $0.00 ) [3] => Array ( [v] => 0.00 [f] => $0.00 ) [4] => Array ( [v] => 45974.86 [f] => $45,974.86 ) [5] => Array ( [v] => 0.00 [f] => $0.00 ) ) ) [4] => Array ( [c] => Array ( [0] => Array ( [v] => Quinto [f] => QUINTO ) [1] => Array ( [v] => 0.00 [f] => $0.00 ) [2] => Array ( [v] => 0.00 [f] => $0.00 ) [3] => Array ( [v] => 1405.8 [f] => $1,405.80 ) [4] => Array ( [v] => 39244 [f] => $39,244.00 ) [5] => Array ( [v] => 0.00 [f] => $0.00 ) ) ) ) ) </pre>