Is there anyway of inserting a value at the end of an array without knowing how many values are in the array ie.
$array[last] = 'value'

i know i could do a count then use this number ie, $array[$count] = 'value' i just wondered if there was a way like $array[last].

cheers

Jamie

    this is the same as
    array_push($array, 'value');
    for better code reading perhaps ... whatever. 😉

      i found that too, however, it will only work if the variable is already initialised, in my case its not 🙁
      and i'm having great trouble with $array[] i think because i'm using a variable variable 🙁(((

      any ideas

        Hmm. Could be a precedence issue - I often confused about where to put the extra {}.

        The documentation says "In order to use variable variables with arrays, you have to resolve an ambiguity problem. That is, if you write $$a[1] then the parser needs to know if you meant to use $a[1] as a variable, or if you wanted $$a as the variable and then the [1] index from that variable. The syntax for resolving this ambiguity is: ${$a[1]} for the first case and ${$a}[1] for the second."

        Is this still true if you substitute [] for [1]?

          Write a Reply...