Is it possible to insert array data in textbox?
This is my array:
[MTS] => Array
(
[103] => Array
(
[0] => MTS
[1] => Lorvia Christine
[2] => 103
[3] => 6/16/2014 9:31
)
)
[SSS] => Array
(
[104] => Array
(
[0] => SSS
[1] => Jannah Curtis
[2] => 104
[3] => 6/28/2014 14:29
)
)
[ITM] => Array
(
[105] => Array
(
[0] => ITM
[1] => Sassy Mica
[2] => 105
[3] => 6/18/2014 9:12
)
)
And I want to make my form like this:
And if this way is impossible can someone recommend me an another way to output it on textbox.
<input type="text" value="<?=$arrayname['arraykey']?>" />
And that's all you need to do.
Related
I started using Blade template engine with codeigniter, and Google Api
i use blade to develope an old project created by another developers for this reason i have to keep the same blade data structure.
this is the Blade code written by a different developpers (i need to keep it ):
#foreach ($analytics['countries'] as $country)
['{{$country['country']}}', {{$country['visits_percent']}}],
#endforeach
this is my PHP code
$this->blade->view()->make('analytics/analytics', ['analytics' => $analytics]);
and this is my $analtics array :
Array
(
[0] => Array
(
[0] => Canada
[1] => 3367
)
[1] => Array
(
[0] => United States
[1] => 202
)
[2] => Array
(
[0] => Malaysia
[1] => 34
)
[3] => Array
(
[0] => Mexico
[1] => 31
)
[4] => Array
(
[0] => Peru
[1] => 23
)
[5] => Array
(
[0] => Brazil
[1] => 21
)
[6] => Array
(
[0] => United Kingdom
[1] => 21
)
[7] => Array
(
[0] => Netherlands
[1] => 17
)
[8] => Array
(
[0] => Nepal
[1] => 14
)
[9] => Array
(
[0] => India
[1] => 12
)
[10] => Array
(
[0] => Belarus
[1] => 11
)
[11] => Array
(
[0] => France
[1] => 9
)
[12] => Array
(
[0] => Ireland
[1] => 9
)
[13] => Array
(
[0] => Germany
[1] => 7
)
[14] => Array
(
[0] => Philippines
[1] => 6
)
[15] => Array
(
[0] => Singapore
[1] => 5
)
[16] => Array
(
[0] => Bangladesh
[1] => 4
)
[17] => Array
(
[0] => Italy
[1] => 4
)
[18] => Array
(
[0] => Serbia
[1] => 4
)
[19] => Array
(
[0] => Australia
[1] => 3
)
[20] => Array
(
[0] => Belgium
[1] => 3
)
[21] => Array
(
[0] => Indonesia
[1] => 3
)
[22] => Array
(
[0] => Iran
[1] => 3
)
[23] => Array
(
[0] => Jordan
[1] => 3
)
[24] => Array
(
[0] => Morocco
[1] => 3
)
[25] => Array
(
[0] => China
[1] => 2
)
[26] => Array
(
[0] => Colombia
[1] => 2
)
[27] => Array
(
[0] => Moldova
[1] => 2
)
[28] => Array
(
[0] => Pakistan
[1] => 2
)
[29] => Array
(
[0] => Poland
[1] => 2
)
[30] => Array
(
[0] => Romania
[1] => 2
)
[31] => Array
(
[0] => South Africa
[1] => 2
)
[32] => Array
(
[0] => Thailand
[1] => 2
)
[33] => Array
(
[0] => Turkey
[1] => 2
)
[34] => Array
(
[0] => Argentina
[1] => 1
)
[35] => Array
(
[0] => El Salvador
[1] => 1
)
[36] => Array
(
[0] => Hong Kong
[1] => 1
)
[37] => Array
(
[0] => Japan
[1] => 1
)
[38] => Array
(
[0] => Kenya
[1] => 1
)
[39] => Array
(
[0] => Latvia
[1] => 1
)
[40] => Array
(
[0] => New Zealand
[1] => 1
)
[41] => Array
(
[0] => Russia
[1] => 1
)
[42] => Array
(
[0] => Saudi Arabia
[1] => 1
)
[43] => Array
(
[0] => South Korea
[1] => 1
)
)
my question is how can i produce the same array structure for blade
thank you
I hope this code useful for you :
Route::get('/test', function (Request $request) {
$analytics=[
[
'Canada',
3367
],
[
'United States',
202
],
[
'Malaysia',
34
],
];
return view('welcome',compact('analytics'));
})
and you can use this code in view :
#foreach( $analytics as $analytic)
<p>
country = {{$analytic[0]}}
<br>
code = {{$analytic[1]}}
<tr>
</p>
#endforeach
This is the array which i get from post
Array
(
[data] => Array
(
[Invoice] => Array
(
[itemNo] => Array
(
[0] => rtgrg
[1] => 4t4t
[2] => ththt
[3] => thth
)
[itemName] => Array
(
[0] => rtgrt
[1] => 4t5t5
[2] => hthtyh
[3] => gnghnn
)
[itemDiscription] => Array
(
[0] => 5tr5t
[1] => t45t4
[2] => tyhthtyh
[3] => gnghnh
)
[price] => Array
(
[0] => 2
[1] => 10
[2] => 9
[3] => 12
)
[itemQuantity] => Array
(
[0] => 2
[1] => 12
[2] => 9
[3] => 9
)
[itemDiscount] => Array
(
[0] => 11
[1] => 0.14
[2] => 0.13
[3] => 0.1
)
[itemTotal] => Array
(
[0] => 333333
[1] => 34535
[2] => 55555555555555
[3] => 666666666
)
[itemStartDate] => Array
(
[0] =>
[1] =>
[2] =>
[3] => 2016-06-17
)
[itemEndDate] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
)
[itemCustomcol] => Array
(
[0] => 4t4t4
[1] => t5trgr
[2] => htht
[3] => gngh
)
[itemCustomcol2] => Array
(
[0] => t4t4t
[1] => rtgtr
[2] => thth
[3] => gng
)
[itemttax2] => Array
(
[0] => tax1
)
[itemttax3] => Array
(
[0] => tax1
)
[itemttax4] => Array
(
[0] => tax1
)
[itemtCsTax] => Array
(
[0] => gngn
)
[itemtCsTaxPer] => Array
(
[0] => 0.1
)
[itemtDiscount] => Array
(
[0] => 0.18
)
[itemtInvReceived] => Array
(
[0] => gngn
)
[itemtInvToReturn] => Array
(
[0] => gngng
)
[itemInvDue] => Array
(
[0] => nghnghng
)
[itemInvComment] => Array
(
[0] => hngnhg
)
)
)
There is a separate table for dynamic input like itemName, itemDiscription to itemCustomcol2 and another table for itemttax2 to itemInvComment .
I tried foreach loop for multiple element array but this doent work for me as it returns a string. one of them is shown below
$capture_field_vals ="";
foreach($_POST["data"]["Invoice"]["itemNo"] as $key => $text_field){
$capture_field_vals .= $text_field .", ";
}
echo $capture_field_vals;
What i want is collect all element[0] and then insert it in a row mysql and then another element another row and so on.
Is there any reason you can't use the following format?
Array
(
[data] => Array
(
[Invoice] => Array
(
[0] => Array
(
[itemNo] => number
[itemName] => name
[itemDescription] => desc
[price] => 0.00
),
[1] => Array
(
[itemNo] => number
[itemName] => name
[itemDescription] => desc
[price] => 0.00
),...
with this method you can loop through retrieving all details of each item in the invoice?
If I have misunderstood your problem, I apologise
I have an array like
$sele_itmid = Array
(
[0] => 1
[1] => 1
[2] => 1
[3] => 4
[4] => 4
)
$fltrd_serl_batch = Array
(
[0] => SAL121
[1] => SAL122
[2] => SAL 145
[3] => M121
[4] => M122
)
At this time i need to combine them like $sele_itmid values as keys $fltrd_serl_batch some thing like
array(
[1] => SAL121
[1] => SAL122
[1] => SAL 145
[4] => M121
[4] => M122
)
I know cant use array_combine because it wont accept duplicate keys. what is the other way to do this? Is there any array function to do this?
$itm_btch = array_map(function($key, $val) {return array($key=>$val);}, $sele_itmid, $fltrd_serl_batch);
print_r($itm_btch );
Array
(
[0] => Array
(
[1] => SAL122
)
[1] => Array
(
[1] => SAL 145
)
[2] => Array
(
[4] => M121
)
[3] => Array
(
[4] => M122
)
)
I have a dataset similar to this in which I am trying to replace the numeric key values within DATA to the corresponding values in COLUMNS. I can do this in a loop but I don't think I'm doing it in the most efficient way possible. Can anyone suggest any nice functions that I haven't considered to accomplish this?
Existing Style
stdClass Object
(
[COLUMNS] => Array
(
[0] => MATCHID
[1] => SEASON
[2] => COMPETITION
[3] => ROUNDID
[4] => ROUNDSORT
[5] => ROUNDNAME
)
[DATA] => Array
(
[0] => Array
(
[0] => 141627
[1] => 2013/2014
[2] => The Scottish Cup
[3] => 18
[4] => 11
[5] => Final
)
[1] => Array
(
[0] => 140895
[1] => 2013/2014
[2] => The Scottish Cup
[3] => 16
[4] => 10
[5] => Semi-Final
)
)
)
Desired Style
stdClass Object
(
[COLUMNS] => Array
(
[0] => MATCHID
[1] => SEASON
[2] => COMPETITION
[3] => ROUNDID
[4] => ROUNDSORT
[5] => ROUNDNAME
)
[DATA] => Array
(
[0] => Array
(
[MATCHID] => 141627
[SEASON] => 2013/2014
[COMPETITION] => The Scottish Cup
[ROUNDID] => 18
[ROUNDSORT] => 11
[ROUNDNAME] => Final
)
[1] => Array
(
[MATCHID] => 140895
[SEASON] => 2013/2014
[COMPETITION] => The Scottish Cup
[ROUNDID] => 16
[ROUNDSORT] => 10
[ROUNDNAME] => Semi-Final
)
)
)
foreach ($data->DATA as $key => $array) {
$data->DATA[$key] = array_combine($data->COLUMNS, $array);
}
$data is the object you showed.
Loop trough the data and combine the keys with the data, see array_combine
$data->DATA = array_map(function (array $entry) use ($data) {
return array_combine($data->COLUMNS, $entry);
}, $data->DATA);
I have created a script that generates an array.
This array needs to be stored so that if a user wants to export its contents( eg print ) it may be possible.
This is my array ($doc)
Array
(
[0] => Array
(
[0] => ------
[1] => ---Start----
[2] => -------
[3] => Generated on Saturday, 3rd, August 2013
)
[1] => Array
(
[0] => ------
[1] => -------
[2] => -------
[3] => -----------------------
)
[2] => Array
(
[0] => Tid
[1] => Policy
[2] => Budget
[3] => User
[4] => Capturetime
[5] => Country
)
[3] => Array
(
[0] => 1
[1] => ask
[2] => das
[3] => carol
[4] => 2013-07-09
[5] => Ethiopia
)
[4] => Array
(
[0] => 2
[1] => das
[2] => adsasd
[3] => ck
[4] => 2007-07-13
[5] => Slovakia
)
[5] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
)
[6] => Array
(
[0] => ------
[1] => ---End----
[2] => -------
)
)
Now I save the array to a file:
file_put_contents('array.txt', print_r($printdoc, true));
Then I would like to call back the contents of array.txt to the array $printdoc and use it as an array.
$printdoc = file_get_contents('array.txt', true);
I get $printdoc as a string instead of an array
Any help?
You can use serialize() to convert your array into a serializable string, then store it in a file. When you read the string from the file use unserialze() to convert it back into an array.