I have an function called send message
function sendMessage(){
$content = array(
"en" => 'value1'
);
$headings = array(
"en" => 'value2'
);
$hashes_array = array();
fields = array(
'app_id' => "31fe2347-5f39-4d9f-2222-79bf542f00f9",
'included_segments' => array(
'All'
),
'data' => array(
"foo" => "bar"
),
'contents' => $content,
'headings' => $headings,
'url' => 'http://www.999999.in/view.php?id=[id]',
'chrome_web_image' => 'http://www.99999.in/admin/user_images/[userPic]',
);
And I have an array ready
Array(
[id] => 498
[value2] => యూట్యూబ్లో “భరత్ అనే నేను” అన్ కట్ సీన్లు..!
[value1] => కొరటాల శివ దర్శకత్వం లో సూ...
[value3] => 525722.jpg
)
Now just I need to place array values in function
Please help me on this I tried all echo values
Pass the array as an argument to the function, then access the elements.
function sendMessage($array) {
$content = array(
"en" => $array['value1']
);
$headings = array(
"en" => $array['value2']
);
$hashes_array = array();
$fields = array(
'app_id' => "31fe2347-5f39-4d9f-2222-79bf542f00f9",
'included_segments' => array(
'All'
),
'data' => array(
"foo" => "bar"
),
'contents' => $content,
'headings' => $headings,
'url' => 'http://www.999999.in/view.php?id=' . $array['id'],
'chrome_web_image' => 'http://www.99999.in/admin/user_images/' . $array['value3'],
);
print_r($fields);
}
try like this
$valueArray = ['id' => 498, 'value2' => 'యూట్యూబ్లో “భరత్ అనే నేను” అన్ కట్ సీన్లు..!', 'value1' => 'కొరటాల శివ దర్శకత్వం లో సూ... ', 'value3' => '525722.jpg'];
output
Array
(
[id] => 498
[value2] => యూట్యూబ్లో “భరత్ అనే నేను” అన్ కట్ సీన్లు..!
[value1] => కొరటాల శివ దర్శకత్వం లో సూ...
[value3] => 525722.jpg
)
update your function with following code
function sendMessage($valueArray){
extract($valueArray);
$fields = array(
'app_id' => "31fe2347-5f39-4d9f-2222-79bf542f00f9",
'included_segments' => array('All' ),
'data' => array( "foo" => "bar" ),
'contents' => array( "en" => $value1 ),
'headings' => array( "en" => $value2 ),
'url' => 'http://www.999999.in/view.php?id=[id]',
'chrome_web_image' => 'http://www.99999.in/admin/user_images/[userPic]',
);
print_r($fields);
}
pass the array parameter to the function
sendMessage($valueArray);
output
Array
(
[app_id] => 31fe2347-5f39-4d9f-2222-79bf542f00f9
[included_segments] => Array
(
[0] => All
)
[data] => Array
(
[foo] => bar
)
[contents] => Array
(
[en] => కొరటాల శివ దర్శకత్వం లో సూ...
)
[headings] => Array
(
[en] => యూట్యూబ్లో “భరత్ అనే నేను” అన్ కట్ సీన్లు..!
)
[url] => http://www.999999.in/view.php?id=[id]
[chrome_web_image] => http://www.99999.in/admin/user_images/[userPic]
)