The output I am trying to receive is
"The Interest Rates are:
0.0525
0.0550
0.0575"
This will continue to $InterestRate7 value. I tried to link the new array elements with the old interest rate ($InterestRate1 = 0.0525; $RatesArray[1] = $InterestRate1) but it still does not work for me.Here is my code for extra help.
<?php
$InterestRate1 = 0.0525;
$InterestRate2 = 0.0550;
$InterestRate3 = 0.0575;
$InterestRate4 = 0.0600;
$InterestRate5 = 0.0625;
$InterestRate6 = 0.0650;
$InterestRate7 = 0.0700;
$RatesArray = array(
$RatesArray[1] = "0.0525";
$RatesArray[2] = "0.0550";
$RatesArray[3] = "0.0575";
$RatesArray[4] = "0.0600";
$RatesArray[5] = "0.0625";
$RatesArray[6] = "0.0650";
$RatesArray[7] = "0.0700";);
echo $RatesArray[1];
?>
The array() construct doesn't work quite like what you have here. Try something similar to the example in the php documentation http://php.net/manual/en/language.types.array.php
$RatesArray = array(
1 => "0.0525",
2 => "0.0550",
3 => "0.0575");
Related
how can optimization function this code in PHP smarty?
now I've a code to confuse me, there is a simple code.
$sql_set_land = "select * from set_new_land where id_rent_house =".Tools::getValue("id_rent_house");
//print_r($sql_set_land);
$n_land = Db::rowSQL($sql_set_land,true);
$landTitle1 = $n_land['landTitle1'];
$landTitle2 = $n_land['landTitle2'];
$landBuilderNumber = $n_land['landBuilderNumber'];
$landLandMark = $n_land['landLandMark'];
$land_1 = $n_land['land_1'];
$land_2 = $n_land['land_2'];
$land_3 = $n_land['land_3'];
...
...
...
$land_30 = $n_land['land_30'];
$land_31 = $n_land['land_31'];
$land_32 = $n_land['land_32'];
when I search the code that I need to push the value.
$this->context->smarty->assign([
'park_space' =>$park_space,
'recording_data' =>$recording_data,
'clode_number' => $clode_number,
'ad_choose_top' => $ad_choose_top,
'ad_choose_type' => $ad_choose_type,
'ad_choose_payment_type' => $ad_choose_payment_type,
'ad_choose_payment_type1' => $ad_choose_payment_type1,
'landTitle1' => $landTitle1,
'landTitle2' => $landTitle2,
'landBuilderNumber' => $landBuilderNumber,
'landLandMark' => $landLandMark,
'land_1' => $land_1,
'land_2' => $land_2,
'land_3' => $land_3,
...
...
...
'land_30' => $land_30,
'land_31' => $land_31,
'land_32' => $land_32,
how can optimization function? Can I write to array? if It's can write into array, how can I do?
Your problem is not in the PHP code, it is in the design of your database. Any time you need to have numbers in column names is a sign that you've failed to normalize your data.
If you expanded the *, which is generally good practice to avoid surprises when you make changes to your database, you would have to write this:
select
landTitle1,
landTitle2,
landBuilderNumber,
landLandMark,
land_1,
land_2,
land_3,
land_4,
land_5,
land_6,
land_7,
land_8,
land_9,
land_10,
land_11,
land_12,
land_13,
land_14,
land_15,
land_16,
land_17,
land_18,
land_19,
land_20,
land_21,
land_22,
land_23,
land_24,
land_25,
land_26,
land_27,
land_28,
land_29,
land_30,
land_31,
land_32
from set_new_land
where id_rent_house = :id
With a properly normalised database, you would instead write something like this:
select
SND.landTitle1,
SND.landTitle2,
SND.landBuilderNumber,
SND.landLandMark,
L.landNumber,
L.land
from set_new_land as SND
join lands as L
On L.set_new_land_id = SND.set_new_land_id
where SND.id_rent_house = :id
Then in PHP, you can use the array_column function:
$lands = array_column($dbResults, 'land');
// or, if the land numbers are important
$lands = array_column($dbResults, 'land', 'landNumber');
If you can't fix your data, though, you can transform it into a more sensible form in PHP, with a loop that counts from 1 to 32:
$lands = [];
for ( $landNumber=1; $landNumber<=32; $landNumber++ ) {
$columnName = 'land_' . $landNumber;
$lands[] = $messyDbResults[ $columnName ];
}
I am trying to achieve this output from PHP array.
<Timesheets>
<Timesheet>
<EmployeeID>5e493b2e-c3ed-4172-95b2-593438101f76</EmployeeID>
<StartDate>2013-04-03</StartDate>
<EndDate>2013-04-10</EndDate>
<Status>Draft</Status>
<TimesheetLines>
<TimesheetLine>
<EarningsRateID>0daff504-2d42-4243-bdac-24f2bae0ce7c</EarningsRateID>
<NumberOfUnits>
<NumberOfUnit>8.00</NumberOfUnit>
<NumberOfUnit>8.00</NumberOfUnit>
<NumberOfUnit>8.00</NumberOfUnit>
<NumberOfUnit>8.00</NumberOfUnit>
<NumberOfUnit>8.00</NumberOfUnit>
<NumberOfUnit>0.00</NumberOfUnit>
<NumberOfUnit>0.00</NumberOfUnit>
</NumberOfUnits>
</TimesheetLine>
</TimesheetLines>
</Timesheet>
</Timesheets>
and my php code is (only array)
$new_timesheet = array();
$new_timesheet['Timesheet'] = array();
$new_timesheet['Timesheet']['EmployeeID'] = '8534e85a-e398-4041-99b1-cce51e7a8a02';
$new_timesheet['Timesheet']['StartDate'] = "2018-01-22";
$new_timesheet['Timesheet']['EndDate'] = "2018-01-28";
$new_timesheet['Timesheet']['Status'] = "Draft";
$new_timesheet['Timesheet']['Hours'] = "5.0";
$new_timesheet['Timesheet']['TimesheetLines'] = array();
$new_timesheet['Timesheet']['TimesheetLines']['TimesheetLine'] = array();
$new_timesheet['Timesheet']['TimesheetLines']['TimesheetLine']['EarningsRateID'] = '0daff504-2d42-4243-bdac-24f2bae0ce7c';
$new_timesheet['Timesheet']['TimesheetLines']['TimesheetLine']['NumberOfUnits'] = array();
$new_timesheet['Timesheet']['TimesheetLines']['TimesheetLine']['NumberOfUnits'][]['NumberOfUnit'] = array('8.00');
$new_timesheet['Timesheet']['TimesheetLines']['TimesheetLine']['NumberOfUnits'][]['NumberOfUnit'] = array('9.00');
but unexpectedly I am getting this output
<Timesheets>
<Timesheet>
<EmployeeID>8534e85a-e398-4041-99b1-cce51e7a8a02</EmployeeID>
<StartDate>2018-01-22</StartDate>
<EndDate>2018-01-28</EndDate>
<Status>Draft</Status>
<Hours>5.0</Hours>
<TimesheetLines>
<TimesheetLine>
<EarningsRateID>0daff504-2d42-4243-bdac-24f2bae0ce7c</EarningsRateID>
<NumberOfUnits>
<NumberOfUnit>8.00</NumberOfUnit>
</NumberOfUnits>
<NumberOfUnits>
<NumberOfUnit>9.00</NumberOfUnit>
</NumberOfUnits>
</TimesheetLine>
</TimesheetLines>
</Timesheet>
</Timesheets>
you can see it is repeating "NumberOfUnits" tag, which is incorrect.
Output should be as the first one.
can anybody do this for me?
As per your requirement, you have a NumberOfUnits array inside which there are multiple NumberOfUnit entries.
You can achieve the desired result by assigning to the NumberOfUnit array in the below manner
$new_timesheet['Timesheet']['TimesheetLines']['TimesheetLine']['NumberOfUnits']['NumberOfUnit'][] = '8.00';
$new_timesheet['Timesheet']['TimesheetLines']['TimesheetLine']['NumberOfUnits']['NumberOfUnit'][] = '9.00';
I am having troubles converting a string which contains tab delimited CSV output
into an array. While using the following code :
$data = stream_get_contents($request->getShipmentReport());
I get back data as following:
Date Shipped Comments Feedback Arrived on Time
5/11/15 2 comment response Yes
Now I would like to process this data into an array with the returned headers(line 1) as the index containing the value for each line which follows after that.
I am trying to end up with something like this :
$line['Date'] = 5/11/15
$line['Shipped'] = 2
$line['Feedback'] = response
$line['Arrived on Time'] yes
What would be the best way to achieve this ?
I recommend using a library for handling CSV for example the CSV-Package by The League of Extraordinary Packages
You can pass your data and start working with array structures right away:
$csvString = stream_get_contents($request->getShipmentReport());
$csvReader = \League\Csv\Reader::createFromString($csvString);
$data = $csvReader->fetchAssoc(
array('Date', 'Shipped', 'Comments', 'Feedback', 'Arrived on Time')
);
// Or since line 0 contains header
$data = $csvReader->fetchAssoc(0); // 0 is offset of dataset containing keys
Now your data should be in a structure like:
$data = array(
array(
'Date' => '5/11/15',
'Shipped' => '2',
...
),
array(
...
)
);
You can even filter out specific datasets and all kinds of fancy stuff. Just check the documentation I linked to.
League CSV reader gives me a bad result. I use this instead:
$csvReportString = stream_get_contents($request->getReport());
$csvReportRows = explode("\n", $csvReportString);
$report = [];
foreach ($csvReportRows as $c) {
var_dump($c);
if ($c) { $report[] = str_getcsv($c, "\t");}
}
var_dump($report);
I am trying to CALL WSDL FROM php
http://validator2.addressdoctor.com/addBatch/Batch.asmx?wsdl
define('ADDRESSDOCTOR_WSDL_URL','http://validator2.addressdoctor.com/addBatch/Batch.asmx?wsdl');
define('ADDRESSDOCTOR_USER_LOGIN','myaccount');
define('ADDRESSDOCTOR_USER_PASSWORD','password');
$useinfo = array(
"CustomerID"=>ADDRESSDOCTOR_USER_LOGIN,
"DepartmentID"=>0,
"Password"=>ADDRESSDOCTOR_USER_PASSWORD
);
$addressinfo = array(
"Street"=>"main st",
"Locality"=>"wayne",
"PostalCode"=>"07035",
"Province"=>"NJ",
"Country"=>"USA");
$addressinfo1 = array(
"Street"=>"100 newark tpk",
"Locality"=>"wayne",
"PostalCode"=>"07470",
"Province"=>"NJ",
"Country"=>"USA");
$array_of_add = array("Address"=>$addressinfo,"Address"=>$addressinfo1);
$client = new SoapClient(ADDRESSDOCTOR_WSDL_UR);
$function = $client->Validate(array("addBatchRequest"=>array("Authentication"=>$useinfo,"Parameters"=>$paramenters,**"AddressCount"=>2**,"Addresses"=>$array_of_add)));
$result = $function->ValidateResult;
print_r($result);
It give me error
does not match number of supplied addresses.
If I write
$function = $client->Validate(array("addBatchRequest"=>array("Authentication"=>$useinfo,"Parameters"=>$paramenters,"AddressCount"=>1,"Addresses"=>$array_of_add)));
"AddressCount"=>2 is changed to "AddressCount"=>1
It works and outputs single result for "Address"=>$addressinfo1 even though i have passed two addresses Address"=>$addressinfo,"Address"=>$addressinfo1. I can pass upto 10 count in each batch request. But I am not able to get it. Can please some one help me what I am doing wrong.
I figured it out. I had to put
$array_of_add = array($addressinfo,$addressinfo1);
instead of
$array_of_add = array("Address"=>$addressinfo,"Address"=>$addressinfo1);
I'm having some troubles with NuSOAP trying to send duplicate tags. This is the code i need to send :
<PartNumbers>
<string>string1</string>
<string>string2</string>
</PartNumbers>
I'm doing the call with this code:
$pn[] = 'APPSP2101V2';
$pn[] = 'ME665Y/A';
$PartNumbers = array( 'PartNumbers' => array('string' => $pn));
$result = $client->call('GetDataSheetsLastUpdate', $PartNumbers );
I'm sending those two PartNumbers but instead of send the two codes it's sending the last one "ME665Y/A"
Also if i try
$PartNumbers = array( 'PartNumbers' => array('string' => 'APPSP2101V2', 'string' => 'ME665Y/A'));
$result = $client->call('GetDataSheetsLastUpdate', $PartNumbers );
Only send the last string.
How can i make an array with the same keys but different value to make the XML look like in the beggining of the question.
Thank you in advance to all
With the following code:
$pn[] = 'APPSP2101V2';
$pn[] = 'ME665Y/A';
$PartNumbers = array( 'PartNumbers' => array('string' => $pn));
$result = $client->call('GetDataSheetsLastUpdate', $PartNumbers );
Works perfect , the problema was in the webservice.. if the P/N isn't correct only return the P/N with information on it.