PHP get both array value and array key

后端 未结 4 1145
日久生厌
日久生厌 2020-12-02 20:40

I want to run a for loop through an array and create anchor elements for each element in the array, where the key is the text part and the value is the URL.

How can

4条回答
  •  广开言路
    2020-12-02 21:00

    Like this:

    $array = array(
        'Google' => 'http://google.com',
        'Facebook' => 'http://facebook.com'
    );
    
    foreach($array as $title => $url){
        echo '' . $title . '';
    }
    

提交回复
热议问题