Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the value of an object member that has a pipe?

Tags:

php

Given this object, how do I output the value of pipe|title?

stdClass Object
(
    [profile|title] => John Doe
)

I've never seen a pipe in a member name before.

like image 222
user903277 Avatar asked Oct 21 '11 00:10

user903277


People also ask

What is key value pipe in angular?

The KeyValue Pipe converts given Object or Map into an array of key-value pairs. We can use this with the ngFor to loop through the object keys. The keyValue accepts the one argument compareFn , which we can use to set the custom sort to the pipe.

Can we use object keys in HTML?

Awesome. Setting objectKeys = Object. keys is simplest method I've seen to be able to check the length of an object from the HTML.

How angular pipes work?

You use data binding with a pipe to display values and respond to user actions. If the data is a primitive input value, such as String or Number , or an object reference as input, such as Date or Array , Angular executes the pipe whenever it detects a change for the input value or reference.


2 Answers

You can make use of the curly brackets and put the field name in a string:

$obj->{'profile|title'}
like image 175
Tim Cooper Avatar answered Sep 30 '22 13:09

Tim Cooper


You can use

$obj->{'profile|title'}

Since you're just using it as a stupid data store, you can also cast it as an array

$arr = (array) $obj;
$arr['profile|title'];

This would be more useful if you're using a lot of values out of it this way or you need to iterate over it.

like image 23
Jeff Day Avatar answered Sep 30 '22 13:09

Jeff Day