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
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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.