count function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Scott Castillo

    count function

    The following line prints something:

    echo $keywords[0][3];

    However, when I then use the count function as follows:

    $count = count($keywords[0]);

    echo $count;

    The printed count is only 1.

    I know there are at least 4 items in the array as I proved above.

    The array was created with the preg_split function which I don't think matters.

    I don't know what I'm doing wrong. Seems simple.
  • Pedro Graca

    #2
    Re: count function

    Scott Castillo wrote:[color=blue]
    > The following line prints something:
    >
    > echo $keywords[0][3];
    >
    > However, when I then use the count function as follows:
    >
    > $count = count($keywords[0]);
    >
    > echo $count;
    >
    > The printed count is only 1.
    >
    > I know there are at least 4 items in the array as I proved above.[/color]
    No, you didn't.
    You proved that either $keywords[0] is not an array or it has one item.
    [color=blue]
    > The array was created with the preg_split function which I don't think matters.
    >
    > I don't know what I'm doing wrong. Seems simple.[/color]

    <?php
    $a[0] = 'abcdef';
    echo $a[0][3], "\n";
    echo count($a), "\n\n";

    $b[0][3] = 'something';
    echo $b[0][3], "\n";
    echo count($b[0]), "\n\n";

    $c[0][0] = 'zero';
    $c[0][1] = 'one';
    $c[0][2] = 'two';
    $c[0][3] = 'three';
    $c[0][4] = 'four';
    echo $c[0][3], "\n";
    echo count($c[0]), "\n\n";
    ?>
    --
    --= my mail box only accepts =--
    --= Content-Type: text/plain =--
    --= Size below 10001 bytes =--

    Comment

    Working...