Display array values in PHP

前端 未结 9 2248
名媛妹妹
名媛妹妹 2020-12-01 07:51

So, I\'m working with PHP for the first time and I am trying to retrieve and display the values of an array. After a lot of googling, the only methods I can find for this ar

相关标签:
9条回答
  • 2020-12-01 08:07

    you can easily use join()

    $fruits = array("apple", "banana", "orange");
    print join(" ".$fruits);
    
    0 讨论(0)
  • 2020-12-01 08:10

    You can use implode to return your array with a string separator.

    $withComma = implode(",", $array);
    
    echo $withComma;
    // Will display apple,banana,orange
    
    0 讨论(0)
  • 2020-12-01 08:10

    a simple code snippet that i prepared, hope it will be usefull for you;

    $ages = array("Kerem"=>"35","Ahmet"=>"65","Talip"=>"62","Kamil"=>"60");
    
    reset($ages);
    
    for ($i=0; $i < count($ages); $i++){
    echo "Key : " . key($ages) . " Value : " . current($ages) . "<br>";
    next($ages);
    }
    reset($ages);
    
    0 讨论(0)
提交回复
热议问题