help returning array from function

0 jamie y · October 31, 2014
I am trying to turn a string into an array and return the array to the front end. I call my function like so.

foo('dribble_id', 'googleplus_id','facebook_id','twitter_id');


Here is my foo function that simply echos the values for testing purposes



function foo()
{
    $arg_list = func_get_args();
    
    foreach( $arg_list as $key => $value){
        $options = ot_get_option($value, array());
        $options = $options . " ";
echo $options;
    }
}


When I check the front end, I see what I want to see which is


value1 value2 value3 value4

I have been trying unsuccessfully to return those values as an array using explode()
My problem is that I don't know how to use explode inside the foreach statement or how to get the values out of the foreach. Everything I have tried has returned only 1 index of the array.

Post a Reply

Replies

Oldest  Newest  Rating
0 jamie y · October 31, 2014
figured it out


function foo()
{
    $arg_list = func_get_args();
    
    $social_options = array();
    foreach( $arg_list as $key => $value){
        $social_options[] = ot_get_option($value);
    }
    return $social_options;
}
  • 1

PHP

107,197 followers
About

Server-side, HTML embedded scripting language used to create dynamic Web pages.

Links
Moderators