addressalign-toparrow-leftarrow-leftarrow-right-10x10arrow-rightbackbellblockcalendarcameraccwcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscontroller-playcredit-cardcrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobe--smallglobegmailgooglegroupshelp-with-circleimageimagesinstagramFill 1languagelaunch-new-window--smalllight-bulblightning-boltlinklocation-pinlockm-swarmSearchmailmediummessagesminusmobilemoremuplabelShape 3 + Rectangle 1ShapeoutlookpersonJoin Group on CardStartprice-ribbonprintShapeShapeShapeShapeImported LayersImported LayersImported Layersshieldstar-shapestartickettrashtriangle-downtriangle-uptwitteruserwarningyahooyoutube

Variable oh my Variable (stored in a string in an array)

From: max s.
Sent on: Tuesday, July 5, 2016, 12:44 PM
Hi folks, 

Is it possible to store a variable in a string, then store that string in an array which is held in another file where all arrays for a project are housed? I ask because i get an error telling me i’ve not defined the variable in the file i’m housing the array in - i want to define it in the file i use it in. Is that possible? If so, what am i doing wrong?


i.e., is the following possible or am i being a silly nit?


<? //myArrayFile.php

$aa1 = [
“Title of Description 1"=> “String text goes here...",
“Title of Description 2"=> “{$varibleName} goes here and {$varDiffName}...",
“Title of Description 3"=> “String text goes here with a variable in it {$varOtherName}…"
]

$aa2 = [
“Title of Description 1"=> “String text goes here...",
“Title of Description 2"=> “{$varibleName} goes here and {$varDiffName}...",
“Title of Description 3"=> “String text goes here with a variable in it {$varOtherName}…"
]
?>



<?php  //myCallingFile.php


$varibleName = ‘street name’;
$varDiffName = ‘Apartment number ’;
$varOtherName      = ‘zipcode’;


include ‘myArrayFile.php’;


echo '<h2> My Iteration through the one of the arrays stored in myArrayFile.php </h2>';
foreach($aa1 as $myKey => $myValue) {
echo "<br><br><strong>" . $myKey . "</strong> :" . $myValue;
}





Thank you everyone for any and all help - I hope everyone had a great relaxing weekend
Cheers!








People in this
group are also in: