iam struggling with the following Problem:
I have the following array:
$age = array("Name"=>"35", "Name"=>"37", "Name"=>"43")
Also i have the following public function:
public function get_sitemap_links( $type, $max_entries, $current_page ) {
$links = [
[ 'loc' => 'This should be Number' ],
];
return $links;
}
And i want to generate a foreach loop for loc.
So the "output" should be:
[ 'loc' => '35' ],
[ 'loc' => '37' ],
[ 'loc' => '43' ],
To clarify: I don´t know where to start. It´s a part of wordpress coding snipet for a custom sitemap from rankmath.
I´ve tried various codes. But i am to newbie to coding at php.
Here is what i tried and what i resolve:
public function get_sitemap_links( $type, $max_entries, $current_page ) {
foreach($age AS $Name => $Number){
$links = $Number;
}
}
Sorry, this page could not be found -> This means a problem in the public function. Because the sitemap cant be generated.
public function get_sitemap_links( $type, $max_entries, $current_page ) { $links { foreach($age AS $Name => $Number) {
'loc' = $Number}};return $links; }
syntax error, unexpected 'foreach' (T_FOREACH)
I also tried:
public function get_sitemap_links( $type, $max_entries, $current_page ) {
foreach($age AS $Name => $Number){
$links = [
[ 'loc' = $Number ],
];
return $links;
};
return $links}
syntax error, unexpected '=', expecting ']'