0

I'm a following function to get related keywords from Google.

function getKeywordSuggestionsFromGoogle($keyword) {
    $keywords = array();
    $data = file_get_contents('http://suggestqueries.google.com/complete/search?output=firefox&client=firefox&hl=en-US&q='.urlencode($keyword));
    if (($data = json_decode($data, true)) !== null) {
        $keywords = $data[1];
    }

    return $keywords;
}
function array_values_recursive($ary)  {
    $lst = array();
    foreach( array_keys($ary) as $k ) {
        $v = $ary[$k];
        if (is_scalar($v)) {
            $lst[] = $v;
        } elseif (is_array($v)) {
            $lst = array_merge($lst,array_values_recursive($v));
        }
    }
    return $lst;
}
print_r(getKeywordSuggestionsFromGoogle('Faviana Sweetheart'));

However, the output from this function give Array as

Array ( [0] => faviana sweetheart chiffon gown [1] => faviana sweetheart dress [2] => faviana sweetheart chiffon gown blue [3] => faviana sweetheart chiffon gown red [4] => faviana sweetheart chiffon gown black [5] => faviana sweetheart [6] => faviana sweetheart chiffon [7] => faviana sweetheart gown [8] => faviana strapless sweetheart dress [9] => faviana strapless sweetheart chiffon dress )

I want to know how it possible to output as string variables as

faviana sweetheart chiffon gown, faviana sweetheart dress, faviana sweetheart chiffon gown blue, ..., faviana strapless sweetheart chiffon dress

Thank you

user2971638
  • 477
  • 1
  • 4
  • 12

2 Answers2

2

Use implode() to convert array into string as

$arr=getKeywordSuggestionsFromGoogle('Faviana Sweetheart');

echo $str = implode (", ", $arr);
Saty
  • 22,443
  • 7
  • 33
  • 51
1

In php we can use implode() function to convert an array into string.You can do like this:

$yourArray = getKeywordSuggestionsFromGoogle('Faviana Sweetheart');
$string = implode (", ", $yourArray); 
print_r ($string );
Chonchol Mahmud
  • 2,717
  • 7
  • 39
  • 72