I am working with api with laravel/php and I need the data in following format. It would be great if you can help me or give some hint.
if I do dd() $formData which is submitted from the form I get following array
dd($formData);
dd($formData) gives below result
array:3 [▼
"fname" => "john"
"lname" => "doe"
"age" => "22"
]
Now, Since the $formData array length is 3, I need three array and their key should be assigned to field_name,value should be assigned to value and based on value it should be either text, number or date. Number if value is numeric, date if value is in format 2010-12-01 or 2010/12/01.dd/mm/yyyy otherwise it will be text
Now I need an array that return data in below format. $formData to $newFormData and $newFormData should have following data
output:
[
'field_name' => 'fname',
'value_type' => 'text', //should be text if value is not number or date format
'value' => 'john',
],
[
'field_name' => 'lname',
'value_type' => 'text',//should be text if value is not number or date
'value' => 'doe',
],
[
'field_name' => 'age',
'value_type' => 'number',//should be number if value is numeric
'value' => '22',
]