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

Link to comment
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?

 

 

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',
)

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.