user1562864
user1562864

Reputation: 1

Variable in an array, is this possible? syntax error probably

First I declare a variable that I want to use in multiple arrays through the code. This is a snippet of it where it should work, but it doesn't:

The variable:

$test = '<div id="test"> dit is een test </div>'; 

The array:

$sections[] = array( 
                'title' => $test, 
                'icon' => '/img/icons/home.png' 
                );  

The title is always empty :-/

Thanks !!

Upvotes: 0

Views: 104

Answers (2)

Sumesh TG
Sumesh TG

Reputation: 450

Correct declaration is

$test = '<div id="test"> dit is een test </div>'; 
$sections = array( 
                'title' => $test, 
                'icon' => '/img/icons/home.png' 
                );  

Upvotes: 1

Tiwenty
Tiwenty

Reputation: 763

Try with this code :

$test = '<div id="test"> dit is een test </div>';

$sections['title'] = $test;
$sections['icon'] = '/img/icons/home.png';

echo $sections['title'];

Upvotes: 0

Related Questions