Web Analytics Made Easy -
StatCounter array as a counter - CodingForum

Announcement

Collapse
No announcement yet.

array as a counter

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • array as a counter

    Hi! I want to create a new array and use every field to count a specific value.
    For example
    $myarray[1] //counts how many times the number one appeared

    I need to try something like that $myarray[1]++; //incerement counter...
    but it does not work
    Any suggestion?

  • #2
    PHP Code:
    <?php
    $myarray
    [1] = ;
    $myarray[1]++ ; 
    $myarray[1]++ ;
    $myarray[1]++ ;
    /*or*/
    ++$myarray[1] ;
    ++
    $myarray[1] ;
    echo 
    $myarray[1] ; 
    ?>
    both work for me.
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

    Comment


    • #3
      xm....

      but if we don't know how much the elements of the array are....how we can initialize all the elements of the array with the zero value?
      Thx

      Comment


      • #4
        if the array already exists and has an integer value then you don't need to initialize it here , I was simply showing that incrementation does work.

        when you set your origianl value force it to be an integer value..

        PHP Code:
        <?
        $value
        ='1';
        $array[1] = (int)$value ;//cast to integer
        ++ $array[1] ;
        echo 
        $array[1];
        ?>
        resistance is...

        MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

        Comment

        Working...
        X