473,327 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Array in IF statement?

Hi,

I am trying to write an IF statement that may occur under several different scenarios. I tried to write an array in which each IF statement would occur, but I am not having any luck.

Here is the code I have so far:
Expand|Select|Wrap|Line Numbers
  1.  arsort ( $array );
  2.   $low_to_high = array( "1" => "22", "2" => "23", "3" => "24", "4" => "26", "5" => "27", "6" => "47", "7" => "49", "8" => "50", "9" => "51", "10" => "59", "11" => "61", "12" => "40" );
  3.   if ( $statistic_id = in_array(array_values($low_to_high), $low_to_high))
  4.   asort ( $array );
  5.  
Essentially, if $statistic_id equals any of the values in my array, then I want the script to perform asort instead of arsort.

Any guidance would be highly appreciated!
Sep 28 '10 #1

✓ answered by BaseballGraphs

Hello,

Sorry for my convoluted question. It appears as though this can be solved easily by doing this:
Expand|Select|Wrap|Line Numbers
  1. arsort ($array);
  2. if ($statistic_id == 22 || $statistic_id == 23 || ... || $statistic_id == n)
  3. asort ($array);
  4.  

4 1756
code green
1,726 Expert 1GB
Well where do we start. The index is not needed nor are the quotes
Expand|Select|Wrap|Line Numbers
  1. $low_to_high = array(22,23,24,26,...40);
I am not sure what this means
Expand|Select|Wrap|Line Numbers
  1. if ( $statistic_id = in_array(array_values($low_to_high), $low_to_high))
But in_array() returns true or false so $statistic_id will become a boolean.
You don't need array_values() because in_array() only checks the array values.
So it looks like you are comparing $low_to_high to itself.
Which will always return true so the line following if() will always execute ....I think.

I don't understand what this means
I tried to write an array in which each IF statement would occur
Also
if $statistic_id equals any of the values in my array, then I want the script to perform asort instead of arsort
What is $statistic_id and what is my array?

I suggest a step back and rethink what you are tring to do.
Also study arrays and how the array functions work.
Sep 28 '10 #2
Hello,

Sorry for my convoluted question. It appears as though this can be solved easily by doing this:
Expand|Select|Wrap|Line Numbers
  1. arsort ($array);
  2. if ($statistic_id == 22 || $statistic_id == 23 || ... || $statistic_id == n)
  3. asort ($array);
  4.  
Sep 28 '10 #3
code green
1,726 Expert 1GB
It makes more sense now, but your array idea is tidier
Expand|Select|Wrap|Line Numbers
  1. $low_to_high = array(22,23,24,26,27,47,49,50,51..); 
  2. if(in_array($statistic_id ,$low_to_high))
  3.     asort ($array);
Sep 28 '10 #4
oranoos3000
107 100+
hi my friend
your code that you wrote is seem to be correct only in end line you use

in_array(array_values($low_to_high), $low_to_high)
must be
in_array($low_to_high, $low_to_high)

be successful
Sep 28 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Gactimus | last post by:
I made the program below. It outputs the smallest number in the array. What I would like to know is how do I output the array location. I am at a loss. For example, since the smallest number in...
204
by: Alexei A. Frounze | last post by:
Hi all, I have a question regarding the gcc behavior (gcc version 3.3.4). On the following test program it emits a warning: #include <stdio.h> int aInt2 = {0,1,2,4,9,16}; int aInt3 =...
5
by: Arthur Mnev | last post by:
This is probably beaten to death subject... Does anyone have a good idea of what penalties are for using Fixed statement in c#. On one side it allows for much greater flexibility with casts and...
3
by: Frank | last post by:
C#: cubearray?? int cubeArray = {{{7, 2}, {1, 4}}, {{3, 5}, {4, 4}}}; How do I interpret the above array statement? regards, Frank
35
by: Thierry Loiseau | last post by:
Hello all, and Happy end year 2005 ! Well, I would like to obtain a list of all JavaScript var statement, With "for...in" perharps ? That is bellow my recent test here, but the problem is...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
4
by: Charles | last post by:
Hello Everyone, I have been gettting great feedback from microsoft.public.vc.language group but after doing more searching I think my post should be directed to this group. I am trying to make...
7
by: heddy | last post by:
I have an array of objects. When I use Array.Resize<T>(ref Object,int Newsize); and the newsize is smaller then what the array was previously, are the resources allocated to the objects that are...
5
by: ruomingxu via AccessMonster.com | last post by:
I have an Access database that was designed with Office1995 version. It has a Sub which has array in it and it doesn't seem working with MS Office 2002 XP version. The program is a bit long but...
272
by: Peter Olcott | last post by:
http://groups.google.com/group/comp.lang.c++/msg/a9092f0f6c9bf13a I think that the operator() member function does not work correctly, does anyone else know how to make a template for making two...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.