Reputation: 37
Now i have function and value $data
Query in other file
function template_head($data){
$data[0]["name"];
$data[0]["last-name"];
}
But i have problem when i want to use $data["name"]
for other function
this problem
template_meta($data["name"]);
use
function template_meta($name){
foreach ($name as $var) {
.
.
.
}
Upvotes: 0
Views: 51
Reputation: 72289
An easy example for you:-
abc.php:-
<?php
$data = array(0=>array("name"=>'A',"last-name"=>'B'));
?>
def.php:-
<?php
error_reporting(E_ALL); //check all type of errors
ini_set('display_errors',1); // display those if any happen
include('abc.php'); // include file
function template_M42_head($data){
echo $data[0]["name"].'<br/>';
echo $data[0]["last-name"].'<br/>';
}
function template_M43_head($data){
echo $data[0]["last-name"].'<br/>';
echo $data[0]["name"].'<br/>';
}
template_M42_head($data);
template_M43_head($data);
Output:-
A
B
B
A
What you shown now,do like below:-
$name_data = template_meta($data["name"]);
And either:-
foreach ($name_data as $name_dat){
}
Or
function new_template_meta($name_data){
foreach ($name_data as $var) {
.
.
.
}
new_template_meta($name_data);//call the function
Upvotes: 1