我正在使用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)' –