我正在使用codeigniter.I將稅務明細存儲在會話值中以存儲稅收是包含性的還是排他性的。我需要使用strstr()
來檢查字符串值並進行一些計算。我做了計算波紋管我的控制器的需要更多關於strstr()的知識它不適用於我
<?php
$tax_percentage=$tax['company_tax13'];
if(strstr($service_detail['service_tax'],"inclusive")==true) {
$taxamount=$service_detail['service_price']-($service_detail['service_price']/(1+($tax_percentage/100)));
$grand=$service_detail['service_price'];
}
else {
$taxamount=($service_detail['service_price']*(1+($tax_percentage/100)))-$service_detail['service_price'];
$grand=$taxamount+$service_detail['service_price'];
}
?>
響應,當我運行的代碼是
Array ([service_detail] => Array ([service_price] => 1000 [service_tax] =>"inclusive") [tax] => Array ([0] => Array ([company_tax13] => 14)))
我怎麼能對這個代碼。代碼的任何問題? 我的控制器文件。在這裏,我有一個存儲service_detail['service_tax']
public function add()
{
//if save button was clicked, get the data sent via post
if ($this->input->server('REQUEST_METHOD') === 'POST')
{
$this->load->library('session');
$this->session->unset_userdata('service_detail');
//if the form has passed through the validation
if ($this->form_validation->run())
{
$data_to_store = array(
'id' => $this->input->post('id'),
'service_name' => $this->input->post('service_name'),
'category' => $this->input->post('category'),
'service_tax' => $this->input->post('service_tax'),
'service_length' => $this->input->post('service_length'),
'service_price' => $this->input->post('service_price')
);
//if the insert has returned true then we show the flash message
if($this->service_model->store_service($data_to_store)){
$data['flash_message'] = TRUE;
$this->session->set_flashdata('flash_message', 'updated');
$this->session->set_userdata('service_detail', ['service_price'=>$this->input->post('service_price'),'service_tax'=>$this->input->post('service_tax')]);
redirect(base_url().'admin/service/view');
}else{
$data['flash_message'] = FALSE;
}
}
}
$data['category'] = $this->category_model->get_category();
$data['main_content'] = 'admin/service/add';
$this->load->view('includes/template', $data);
}
爲什麼你使用'的strstr()'? – slash197
來比較我收到的字符串。是否有其他方法? – Anu
嘗試使用'if(strpos($ service_detail ['service_tax'],「inclusive」)> -1)' –