php - Selecting an object using string names? -


i built object, give hex code colored backgrounds dependant on tag post has.

example of object: ($tagcolor)

stdclass object ( [school] => #113730                    [funny] => #ef5017                    [art] => #e2ba17                    [wow] => #164852                    [test] => #9bbb8e                  )  

and example of code i'm trying use display background color: (i'm using laravel framework)

@foreach($links $link)       <?php $tag = $link->tags; ?>       <span class="tagcolor" style="background: {{ $tagcolor->$tag }}"></span> @endforeach 

if use normal text select object value, works fine:

$tagcolor->test 

returns:

#9bbb8e 

how can select object value via string?

does laravel allow regular php tags? suspect not. line doesn't work:

<?php $tag = $link->tags; ?> 

this should allow omit line:

  <span class="tagcolor" style="background: {{ $tagcolor->{$link->tags} }}"></span> 

Comments

Popular posts from this blog

hibernate - How to load global settings frequently used in application in Java -

python 3.x - Mapping specific letters onto a list of words -

objective c - Ownership modifiers with manual reference counting -