Jump to content

Mulitpul variables into one


almightyegg

Recommended Posts

I have this script:

if($crops[start2] > $gap5start){
$select2 = "$crops[start2]";
echo "<br><br><br>$select 2<br><br><br>";
}
if($crops[start3] > $gap5start){
$select3 = "$crops[start3]";
echo "<br><br><br>$select 3<br><br><br>";
}
if($crops[start5] > $gap5start){
$select5 = "$crops[start5]";
}

 

Then I want to put the $selectX variables into a min() function.

As you probably know you need a comma and a space between eache vairable in the min() func.

 

So I was wondering if there was a function that I could use to stitch these together into one variable:

min($variable);

The problem is that the values aren't always set, and if they aren't set then you don't need a comma space

 

Hope that made sense

Link to comment
https://forums.phpfreaks.com/topic/99422-mulitpul-variables-into-one/
Share on other sites

I managed to sort that but I have a similar issue elsewhere:

$gaps = array($gap1start, $gap2start, $gap3start, $gap4start, $gap5start, $gap6start);

$count = count($gaps);

echo "$count";

 

I was hoping that would count  the variables that are set.

In my case for testing $gap1start, $gap2start, $gap4start and $gap4start are all empty, so I want it to count 2 (as only 2 of the array actually have any value)

 

Is there another way?

I managed to sort that but I have a similar issue elsewhere:

$gaps = array($gap1start, $gap2start, $gap3start, $gap4start, $gap5start, $gap6start);

$count = count($gaps);

echo "$count";

 

I was hoping that would count  the variables that are set.

In my case for testing $gap1start, $gap2start, $gap4start and $gap4start are all empty, so I want it to count 2 (as only 2 of the array actually have any value)

 

Is there another way?

 

 

You could go through the array and remove empty values, but it seems there would be a better way using an array from the beginning. So, store everything in $gaps from the start, but if you don't use #2, just don't set the value for #2. So you're array would end up looking like:

array(
  1 => 'value 1',
  3 => 'value 3',
  4 => 'value 4',
)

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.