E
E
emerysh2018-04-26 08:54:07
PHP
emerysh, 2018-04-26 08:54:07

How to get individual elements of a php array?

Help please,
There is a function in which there are arrays (given by the plugin)

arrays
$icons['avatar-upload'] = array(
        'content'=> '<span><input type="file" id="userpicupload" accept="image/*" name="userpicupload"></span>',
        'atts' => array(
            'title' => __('Avatar upload','wp-recall'),
            'url' => '#'
        )
    );
    
    if(get_user_meta($user_ID,'rcl_avatar',1)){
        $icons['avatar-delete'] = array(
            'atts' => array(
                'title' => __('Delete avatar','wp-recall'),
                'href' => wp_nonce_url( rcl_format_url(get_author_posts_url($user_ID)).'rcl-action=delete_avatar', $user_ID )
            )
        ); 
}
return $icons;

In another file, this function is called, it happens
enumeration
foreach($icons as $icon ){
        $atts = array();
        if(isset($icon['atts'])){
            foreach($icon['atts'] as $attr => $val){
                $val = (is_array($val))? implode(' ',$val): $val;
                $atts[] = $attr.'="'.$val.'"';
            }
        }
        $string = '<a '.implode(' ',$atts).'>';
        if(isset($icon['content'])) 
            $string .= $icon['content'];
        $html[] = $string;
    }
   echo implode('',$html);
and creating elements. Is there an option to optimize, in php quite recently, is it difficult to come up with something?
Or how can I separately receive , sort through, and so on. and why doesn't it work correctly? $icons['avatar-upload'], $icons['avatar-delete']
foreach($icons['avatar-upload'] as $icon )

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
emerysh, 2018-04-26
@emerysh

Everything is elementary simple .. as it turned out)
Firstly: the enumeration should have been of this kind Secondly: then there should be a check, something similar to this Good luck everyone foreach($icons as $icon_id => $icon )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question