Display array values only

Asked

Viewed 1,365 times

2

I am a beginner in PHP and I am currently studying the arrays, and I have a silly question.

When I print my arrays, it comes this 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 the 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

  • I changed my question, because the sites did not help me.

  • 2

    Where does this array come from? Your question is very confusing.

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 working: http://ideone.com/kvF17H

I got the @Maniero tip in this post.

0

Use the php native function

array_values($array);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.