Jump to content

fill aray with keys and values


clankill3r

Recommended Posts

atm i have this in a function:

 

$returnInfo = array();

$returnInfo["totalWords"] = $totalWords;
$returnInfo["uniqueWords"] = count($uniqueWords);
$returnInfo["positiveWords"] = $positiveWords;
$returnInfo["negativeWords"] = $negativeWords;
$returnInfo["rating"] = $mappedrating;

return $returnInfo;	

 

If i recursive print it it says Array instand of my expected values.

 

p.s., i have found examples where the array get's created in 1 line with all there values but i prefer not to do that since it will be a very long line.

Link to comment
https://forums.phpfreaks.com/topic/252855-fill-aray-with-keys-and-values/
Share on other sites

If i recursive print it it says Array instand of my expected values.

 

p.s., i have found examples where the array get's created in 1 line with all there values but i prefer not to do that since it will be a very long line.

 

When you say recursive print, what do you mean?  using print_r or var_dump?

 

As for the one line thing, I assume your talking about setting the keys/values inside the array() construct.  It doesn't have to be on one line:

$returnInfo = array(
'totalWords' => $totalWords,
'uniqueWords' => count($uniqueWords),
'positiveWords' => $positiveWords,
'negativeWords' => $negativeWords,
'rating' => $mappedrating
);

return $returnInfo;

 

Doesn't really matter one way or the other though, just a matter of preference.

 

Are you just trying to print the entire array? You can't print or echo an array - only individual array values.

 

To get the whole array use

 


print_r($Name_of_Array);

 

 

atm i have this in a function:

 

$returnInfo = array();

$returnInfo["totalWords"] = $totalWords;
$returnInfo["uniqueWords"] = count($uniqueWords);
$returnInfo["positiveWords"] = $positiveWords;
$returnInfo["negativeWords"] = $negativeWords;
$returnInfo["rating"] = $mappedrating;

return $returnInfo;	

 

If i recursive print it it says Array instand of my expected values.

 

p.s., i have found examples where the array get's created in 1 line with all there values but i prefer not to do that since it will be a very long line.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.