echo key and value of an array without and with loop

前端 未结 11 2026
野的像风
野的像风 2020-12-29 20:47

This is an array i have


How do i get to echo something

11条回答
  •  清酒与你
    2020-12-29 21:45

    A recursive function for a change;) I use it to output the media information for videos etc elements of which can use nested array / attributes.

    function custom_print_array($arr = array()) {
        $output = '';
        foreach($arr as $key => $val) {
            if(is_array($val)){
                $output .= '
  • ' . ucwords(str_replace('_',' ', $key)) . ':
      ' . custom_print_array($val) . '
    ' . '
  • '; } else { $output .= '
  • ' . ucwords(str_replace('_',' ', $key)) . ': ' . $val . '
  • '; } } return $output;

    }

提交回复
热议问题