I need to add a new line inside an array. If possible in a specific position (see below). But this new line should only be added if a determined variable is equal something.
This is my array:
$post_data = array(
'check_type_diff' => '0',
'parent_category' => '1000',
'category_group' => $category,
);
But depending on variable ($typeword and $typevalue), it add a new value:
$post_data = array(
'check_type_diff' => '0',
'parent_category' => '1000',
'apartament_type' => '1', // this is new
'category_group' => $category,
);
But this new key and value needs to change depending on a variable, I have called it $typeword and $typevalue, so it should be something like:
$post_data = array(
'check_type_diff' => '0',
'parent_category' => '1000',
$typeword => $typevalue,
'category_group' => $category,
);
So... if this $typeword is Apartament or House, it prints a new key and value inside of this array. If $typeword is Store, it should not print this new line in the array.
So let's suppose $typeword is House:
$post_data = array(
'check_type_diff' => '0',
'parent_category' => '1000',
'house_type' => '2', // this is new
'category_group' => $category,
);
If $typeword is Store:
$post_data = array(
'check_type_diff' => '0',
'parent_category' => '1000',
'category_group' => $category,
);
What I'm trying to add below array:
// ARRAY START
$post_data = array(
'check_type_diff' => '0',
'parent_category' => '1000',
'category_group' => $category,
);
// ARRAY END
// Try to merge a new part of array
if ($typeword == 'Apartament' || $typeword == 'House') {
$wordtypeword = array("Apartament","House");
$correctword = array("apartment_typeword","home_typeword");
$word = str_replace($wordtypeword, $correctword, $typeword);
$typevaluenew = array("1","1","2","3","1","2");
$newtypeword = str_replace($wordtypeword, $typevaluenew, $typeword);
$typevalue = $xml->stuff[$i]->typeword = $newtypeword;
$post_data["$word"] = array ("$typevalue"); //Now I don't know how to to add this into the array, this is not working.
}
How can I achieve this?