Weird array

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dominik B.

    Weird array

    I'm executing these commands:

    $text="example text";
    $parts=explode( " ", $text);
    $result=$parts[0];

    $result becomes a weird array.

    echo "$result" prints 'example',

    but if I use function count_chars($re sult) i got error message, that $result
    is an array not a string.

    Please tell me how to make my $result be a string

    Thanks

    Domin
    domin(at)zyx.pl


  • Eric Veltman

    #2
    Re: Weird array

    Hello Dominik,

    Dominik B. wrote:
    [color=blue]
    > I'm executing these commands:
    >
    > $text="example text";
    > $parts=explode( " ", $text);
    > $result=$parts[0];
    >
    > $result becomes a weird array.
    >
    > echo "$result" prints 'example',
    >
    > but if I use function count_chars($re sult) i got error message, that
    > $result is an array not a string.
    >
    > Please tell me how to make my $result be a string[/color]

    There's nothing wrong with the code you posted,
    I tried it on my machine.

    What may be causing some confusion is count_chars().
    Please realize that this function is _not_ for getting
    the string length. Instead it by default returns an array
    of all possible characters and the number of times they occur
    in the string.

    If you want a function that simply returns the string length,
    then strlen() is what you're looking for.

    Best regards,

    Eric

    Comment

    Working...