0

still learning some of the finer parts of PHP, i have a function that returns an array of arrays. And on the times that it is only returning a single "array" i use the below code to save having to reference it as a multi dimensional array. Is there a way to do this on a single line of code? i know it doesnt make much of a differance in this specific scenrio, but just curious if i am missing a short hand of php that might be handy other times.

$res_resource=fetch($stmt_resource);  //returns array of arrays
$res_resource=$res_resource[0];
2

1 Answer 1

1

As of PHP 5.4.0:

$res_resource = fetch($stmt_resource)[0];
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your response. I actually tried this, but Dreamweaver views it as an error, so i assumed it didnt work. While this does work in php 5.4, unfortunetly because Dreamweaver views it as an error, code hint stops working, which is not a good trade off :-D. Thank you again for your response, and this definetly works and functions as intended.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.