Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Oct 2012
    Location
    mother land --india
    Posts
    164
    Thanks
    38
    Thanked 2 Times in 2 Posts

    required a loop for array values

    Hi All,

    I am on assignment and need a for loop to check whether

    0<1
    1<2
    2<3....on 20

    I now i am opening a ticket for small loop but I have tried in many ways i don't see loop is working for me ... so i have raised ticket here.

    I am using below code
    PHP Code:
    $array=array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20);
    $i=0;
    $j=1;
    if(
    $array[$j]<= $array[$i] && $array[$j]!=null)
    {
    $i++;
    $j++;
    $_SESSION['Notify']['type'] = 'error Message:';
    $_SESSION['Notify']['msg'] = "$array[$j]</b> cannot be lesser then array[$i]!!!";
    header("location:")or die("record not inserted");

    Last edited by nani_nisha06; 03-03-2013 at 04:59 PM.

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,026
    Thanks
    23
    Thanked 588 Times in 587 Posts
    PHP Code:
    <?php
    $array
    =array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20);

    for(
    $i 0$i 20$i++)
    {
        if(
    $array[$i] < $array[$i 1])
            echo 
    "Yes for ".$i "<br />";
    }

    ?>

  • #3
    Regular Coder
    Join Date
    Oct 2012
    Location
    mother land --india
    Posts
    164
    Thanks
    38
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by sunfighter View Post
    PHP Code:
    <?php
    $array
    =array(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20);

    for(
    $i 0$i 20$i++)
    {
        if(
    $array[$i] < $array[$i 1])
            echo 
    "Yes for ".$i "<br />";
    }

    ?>
    It worked like a charm also, can you help me on similar sort of function.

    I have a form with 4 field, input type is date time.

    And in backend I have called all the values via array, but the really issue is user will not enter all the values at same time lets say.

    [0] => 01/03/2013

    then I want next field to validate with above field.

    example. if user enter second value as [1] => 28/02/2013, it should compare with above i.e., [1]>=[0] if yes update db else redirect.

    in the same third value to compare with second value like [2] >=[1] if yes update db else redirect

    I have tried lot to complete above but no sucess

    please help me, with small mistake it is taking both values in to DB...I know i am messing up with one if condition but not able to figure out....any help is really appreciated....
    Last edited by nani_nisha06; 03-03-2013 at 07:47 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •