Jump to content

[SOLVED] $column = mysql_fetch_row($stmt)[0]; why not?


Recommended Posts

Hi folks!

 

This don't work: $column = mysql_fetch_row($stmt)[0];

I have to do this:

$row = mysql_fetch_row($stmt);

$column = $row[0];

 

:-\

Is there a way to do it in a less verbose way?

I think that the php guys should implement this in a new release. I'm using 5.2.5.

You're welcome.

 

That's the problem, $column = mysql_fetch_row($stmt)[0]; should work.

 

No, it shouldn't work at all. mysql_fetch_array() is not an array, it's a function. You can only call an index (ex: [0]) on an array. Functions don't have indexes. So you can't call an index on mysql_fetch_array(), as you are trying to call an index on a function.

 

The function returns an array. That means that the value it spits out is an array. The function itself isn't an array, only the value it produces. So you can call an index on $column, as it contains the value that mysql_fetch_array() gave it, but you cannot call an index on the function itself.

you did'nt understand. here is a Java example.

 

public class MyArray {

public static String[] returnArray() {
	String[] newArray = {"Hello", "World"};
	return newArray;
}

public static void main(String[] args) {
	System.out.println(returnArray()[0]); // prints Hello. NO PROBLEM!!!
}
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.