开发者

Remove index key from Array for accessing to object?

How do I remove Index key from array?

For example:

$getProduct = Product::find($product->ProductID);

and the array structure will look something like this:

Array
(
    [0] => Product Object
        (
            [id] => 26552
            [name] => Product Name One
        )

)

To get t开发者_StackOverflowhe value of name, I have to do this:

echo $getProduct[0]->name;

I want to get the value like this:

echo $getProduct->name;


$getProduct = $getProduct[0]; 

will put the first item in the array into it's own variable, from which you can then access

$getProduct->name

However I would suggest putting it into a variable with a different name for the sake of your code readability, maybe:

$product = $getProduct[0];
echo $product->name;


To get the value as you want, you should change your class "Product" in the way it returns you the object you are initializing after calling the find method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜