0

I have this get_all function:

function get_all($query)
{
    $res = mysql_query($query);
    $arr_res = array();
    while($row = mysql_fetch_array($res))
        $arr_res[] = $row;
    mysql_free_result($res);

    return $arr_res;
} 

It returns this array of data, which is what I need, but I don't want the first item of each array "[0]" to be returned with it:

   Array
    (
        [0] => Array
            (
                [0] => gallery-1-1310312288_logo.jpg
                [post_image] => gallery-1-1310312288_logo.jpg
            )

    )

How can I alter the function to drop this extra item?

1 Answer 1

4

Change this line:

while($row = mysql_fetch_array($res, MYSQL_ASSOC))

By default mysql_fetch_array will return the numerical array index and the associative one - adding the second parameter will make the function only return the associate index.

Sign up to request clarification or add additional context in comments.

1 Comment

or you can use explicitly mysql_fetch_assoc which essentially does the same thing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.