Read array in php?

I’m trying to add some custom user meta on the registeration. For example, I have field to set a fruit :

function some_fruits($fruit= false) {
$fruits= array();
$fruits[‘1’] = ‘Apple’;
$fruits[‘2’] = ‘Banana’;
$fruits[‘3’] = ‘Apricot’;
if($fruit) {
return $fruits[$fruit];
} else {
return $fruits;
}}

But when I call this field with

$display_fruit= get_user_meta($user_id, ‘fruit’, true);

it displays 1 instead of Apple. How can I solve this ?

Read more here:: Read array in php?

Leave a Reply

Your email address will not be published. Required fields are marked *