Jump to content

Array help


amg182

Recommended Posts

Hi.

 

I have an multidemesional array that looks like this:

 


$numbers=array("1"=>'under 5',"2"=>'under 5',"3"=>'under 5',"4"=>'under 5');

 

Is it possible to write the array like this?(without using loops)

 

$numbers=array("1-4"=>'under 5');

or even:

$numbers=array("1,2,3,4"=>'under 5');

 

Thanks in advance.

 

Link to comment
https://forums.phpfreaks.com/topic/247781-array-help/
Share on other sites

I am trying to echo out a particular comment depending on what is entered witihn a form(text input).

 

So if someone enters a value between 1-1000 it would echo out "Under 1000".

The problem i have is that i users can enter a value between 0 - 100,000.

Ideally i would like the text echo out to the nearest thousand so if someone entered 5400 it would echo out "under 6000".

 

Any ideas?

 

Thanks again.

Link to comment
https://forums.phpfreaks.com/topic/247781-array-help/#findComment-1272424
Share on other sites

That can be done with a simple calculation. No need to go through the hassle of putting all the values in an array. This should get you on the right track.

 

$val = 65432;
$m = ceil($val/1000);
echo "Less than $m,000";  // Returns "Less than 66,000"

Link to comment
https://forums.phpfreaks.com/topic/247781-array-help/#findComment-1272430
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.