Display only array values

2

I'm a PHP developer and I'm currently studying the arrays, and I'm having a silly question.

When I print my arrays, it comes that way

Array (
  [0] => Array ( [0] => 10 )
  [1] => Array ( [0] => 20 )
  [2] => Array ( [0] => 30 )
  [3] => Array ( [0] => 40 )
  [4] => Array ( [0] => 50 )
)

My interest is that only numbers are displayed.

10, 20, 30, 40 50

php code

while (($linha = fgetcsv($file)) !== FALSE)
{

  $carros[] = $linha;
  //print_r($linha);

}

fclose($file);
print_r($carros);

All help will be welcome

    
asked by anonymous 08.11.2015 / 19:25

2 answers

2

Well, based only on the Array you showed in the question, to display only the values you can use for or foreach :

$arr = Array (
    0 => Array ( 0 => 10 ),
    1 => Array ( 0 => 20 ),
    2 => Array ( 0 => 30 ),
    3 => Array ( 0 => 40 ),
    4 => Array ( 0 => 50 )
);
foreach($arr as $value){
    echo $value[0]. " ";
}

See it working: link

I took the @bigown hint in this post .

    
08.11.2015 / 23:05
0

Use the native php function

array_values($array);
    
12.10.2016 / 21:56