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

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -