[Solved] Output specified value from function with array – PHP [closed]


Based on “if for example will be “=>” after the first one, or the second, that’s what i want” i think you want to find out value from array based on the string passed to function, So do like below:-

<?php
function getInfo($string) {
   $info = array(
    'some value',
    'some value 2' => 'some sub-value'
   );
   return $info[$string];
}
?>

<div class="input">
    <span><?php echo getInfo('some value'); ?></span><!-- echo is missed-->
</div>

Note:- Make sure your each array index have some value otherwise nothing will print (in case here for some value).

3

solved Output specified value from function with array – PHP [closed]