Jump to content

Addition


anevins

Recommended Posts

Hello,

 

I have an array with multiple values,

$sentiment_example = array("Wrapped" => 6, "in" => 3, "my" => 5, "blanket" => 7, "always" => 4, "makes" => 6, "me" => 6,
						  "feel" => 5, "a" => 1, "little" => 2, "better" => 7, "when" => 3, "I'm" => 4, "not" => 3,
						  "feeling" => 5, "to" => 1, "well" => 6);

 

I'm trying to multiply each value with an integer,


foreach ( $sentiment_example as $word ) {

$integer = 1;					
$multiplication += $integer * $anew_sentiment;

}

// Using $multiplication here

 

Currently $multiplication holds 17 integers, I just want the last integer. How can I retrieve the last integer?

 

 

 

 

Link to comment
Share on other sites

Hello,

 

I have an array with multiple values,

$sentiment_example = array("Wrapped" => 6, "in" => 3, "my" => 5, "blanket" => 7, "always" => 4, "makes" => 6, "me" => 6,
						  "feel" => 5, "a" => 1, "little" => 2, "better" => 7, "when" => 3, "I'm" => 4, "not" => 3,
						  "feeling" => 5, "to" => 1, "well" => 6);

 

I'm trying to multiply each value with an integer,


foreach ( $sentiment_example as $word ) {

$integer = 1;					
$multiplication += $integer * $anew_sentiment;

}

// Using $multiplication here

 

Currently $multiplication holds 17 integers, I just want the last integer. How can I retrieve the last integer?

what do you want to arciheve?

Link to comment
Share on other sites

@hakimserwa

 

I want to achieve $integer times the $word value, for each word.

Then I want to add each result (of $integer * $word) into a variable, $multiplication.

 

Using the $sentiment_example in my first post, $multiplication should hold only 74.

 

@jesirose

 

I don't see the consequence of an integer being more than one digit.

The $sentiment_example is an extraction from a table within the database, it's already in there.

 

Link to comment
Share on other sites

As I haven't explained properly, this is the sentiment-deriving process from tweets, Twitter that I want to implement;

 

The average sentiment for the tweet text is calculated by finding the frequency that each word appears in the tweet,

multiplying the sentiment for each word from the ANEW dataset by the frequency,

then dividing theresulting value by the frequency

Robert Hawkes (2011)

 

I don't have the ANEW dataset yet, so I'm simulating it with $sentiment_example.

Link to comment
Share on other sites

You could definitely do all of that in SQL. Once you have the array of each of the words, you could use IN().

 

 

 

In your example you're multiplying by 1, so it's pointless. You also called this "addition", did multiplication, then asked for something unrelated.

$multiplication += $integer * $anew_sentiment;

 

Currently $multiplication holds 17 integers, I just want the last integer. How can I retrieve the last integer?

 

It doesn't hold 17 integers, it holds the result of several computations. You're talking about using it as an array, and the help you got used it as a string, and you thought that would work.

 

It's impossible to tell what you really want from the code you show us.

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.