Jump to content

Adding and arrays...


spfoonnewb

Recommended Posts

I have been working on this for a while.. and cannot figure it out.

 

It currently outputs

 

1 +1 +1 +1 +1 +1 +1 +1 +1 +1 +

 

I want it to add them together..

 

<?php

for ($xz = 1; $xz <= 10; $xz++) {
$times[] = "1";
}
foreach ($times as $tt) {
$var[] = "$tt";
}

foreach ($var as $tt2) {
echo "$tt2 +";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/46065-adding-and-arrays/
Share on other sites

Ok that adds them together, but how can I make a string that I can use later in an if statement?

 

I want amt, to be equal to the values from the array.. but appear the way I have it below.

 

Example:

 

<?php

$amt = "1 + 1 + 1 + 1 + 1 + 1 + 1";

if ($total = $amt) {
   //Do something
}
?>

 

Link to comment
https://forums.phpfreaks.com/topic/46065-adding-and-arrays/#findComment-223823
Share on other sites

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.