fastsol1
09-01-2012, 03:23 PM
So I have these 2 arrays for example
$form_fields = array(
array("tag" => array("label"),
"text" => "product name",
"name" => "pname",
"class_fields" => TRUE,
"type" => "text",
"required" => TRUE,
"value_results_name" => "prod_name",
"admin_notes" => FALSE,
"options" => array(),
),
array("tag" => array("label"),
"text" => "part number",
"name" => "pnum",
"class_fields" => TRUE,
"type" => "text",
"required" => TRUE,
"value_results_name" => "prod_number",
"admin_notes" => FALSE,
"options" => array(),
));
// 2nd array
$add_fields = array(
array("tag" => array("function"),
"text" => "vehicle:",
"name" => "vehicle",
"class_fields" => TRUE,
"type" => "text",
"required" => FALSE,
"value_results_name" => "email",
"admin_notes" => FALSE,
"options" => array(),
"function" => $results['v_year'].' '.$results['v_make'].' '.$results['v_model']
),
);
What I want is to insert the $add_fields array into the middle of the form_fields array. Now normally the form_fields array has several more indexes in it than just 2, I am just doing 2 for this example. I was trying to use array_splice() to join the 2 arrays in the index order I wanted but for some reason I can't get it to output any thing when I try this. I am not sure if maybe array_splice doesn't support the ability to do this with multi-dimensional arrays, so that might be the real issue. Here is the way I tried the splice, which is an example from the php.net page.
$count = count($form_fields)-1;
$new_fields = array_splice($form_fields, $count, 0, $add_fields);
print_r($new_fields);
Which according to my knowledge should result in this array
$new_fields = array(
array("tag" => array("label"),
"text" => "product name",
"name" => "pname",
"class_fields" => TRUE,
"type" => "text",
"required" => TRUE,
"value_results_name" => "prod_name",
"admin_notes" => FALSE,
"options" => array(),
),
array("tag" => array("function"),
"text" => "vehicle:",
"name" => "vehicle",
"class_fields" => TRUE,
"type" => "text",
"required" => FALSE,
"value_results_name" => "email",
"admin_notes" => FALSE,
"options" => array(),
"function" => $results['v_year'].' '.$results['v_make'].' '.$results['v_model']
),
array("tag" => array("label"),
"text" => "part number",
"name" => "pnum",
"class_fields" => TRUE,
"type" => "text",
"required" => TRUE,
"value_results_name" => "prod_number",
"admin_notes" => FALSE,
"options" => array(),
))
Any insight into this would be greatly appreciated.
$form_fields = array(
array("tag" => array("label"),
"text" => "product name",
"name" => "pname",
"class_fields" => TRUE,
"type" => "text",
"required" => TRUE,
"value_results_name" => "prod_name",
"admin_notes" => FALSE,
"options" => array(),
),
array("tag" => array("label"),
"text" => "part number",
"name" => "pnum",
"class_fields" => TRUE,
"type" => "text",
"required" => TRUE,
"value_results_name" => "prod_number",
"admin_notes" => FALSE,
"options" => array(),
));
// 2nd array
$add_fields = array(
array("tag" => array("function"),
"text" => "vehicle:",
"name" => "vehicle",
"class_fields" => TRUE,
"type" => "text",
"required" => FALSE,
"value_results_name" => "email",
"admin_notes" => FALSE,
"options" => array(),
"function" => $results['v_year'].' '.$results['v_make'].' '.$results['v_model']
),
);
What I want is to insert the $add_fields array into the middle of the form_fields array. Now normally the form_fields array has several more indexes in it than just 2, I am just doing 2 for this example. I was trying to use array_splice() to join the 2 arrays in the index order I wanted but for some reason I can't get it to output any thing when I try this. I am not sure if maybe array_splice doesn't support the ability to do this with multi-dimensional arrays, so that might be the real issue. Here is the way I tried the splice, which is an example from the php.net page.
$count = count($form_fields)-1;
$new_fields = array_splice($form_fields, $count, 0, $add_fields);
print_r($new_fields);
Which according to my knowledge should result in this array
$new_fields = array(
array("tag" => array("label"),
"text" => "product name",
"name" => "pname",
"class_fields" => TRUE,
"type" => "text",
"required" => TRUE,
"value_results_name" => "prod_name",
"admin_notes" => FALSE,
"options" => array(),
),
array("tag" => array("function"),
"text" => "vehicle:",
"name" => "vehicle",
"class_fields" => TRUE,
"type" => "text",
"required" => FALSE,
"value_results_name" => "email",
"admin_notes" => FALSE,
"options" => array(),
"function" => $results['v_year'].' '.$results['v_make'].' '.$results['v_model']
),
array("tag" => array("label"),
"text" => "part number",
"name" => "pnum",
"class_fields" => TRUE,
"type" => "text",
"required" => TRUE,
"value_results_name" => "prod_number",
"admin_notes" => FALSE,
"options" => array(),
))
Any insight into this would be greatly appreciated.