php - EDIT: how to automatically add data from a field when called
问题描述
how to automatically add data from a field when called.
example:
value of field
is = 1AA/example/example
iam using foreach
foreach ($datanomor as $row){
$var=$row->MaxCode;
echo $var;
}
the result is
1AA/example/example
i want to add operation on (1+ 1AA/example/example)
so what must i do when i call the field, result will show:
2AA/example/example
***edit
have table with name t_surat_keluar
and query to call value of field in my controller is :
$datanomor = $this->db->query("SELECT max(nomor_surat) as maxKode")
->('FROM t_surat_keluar where id_jenissurat=$row->id_jenissurat')
->result();
$data['datanomor']=$datanomor;
the value is 001/smk/ck/2018
In my view i run this script to call that value:
foreach ($datanomor1 as $row) {
$var = $row->maxKode;
echo $var;
}
Now I want to ask, how can I change directly that value (001/smk/ck/2018)
to (002/smk/ck/2018)
when i calling from script ?.
sorry my english is bad.
***edit now i can change directly that value with this script
foreach ($datanomor1 as $row){
$var=$row->maxKode;
$var[2] = (int)$var[2]+1;
echo $var;
}
the new problem is when last value (009/smk/ck/2018)
if i use this script:
$var[2] = (int)$var[2]+1;
output will show (**001**/smk/ck/2018)
not (**0010**/smk/ck/2018)
解决方案
据我了解,你想对你的 var 上的第一个字符进行操作,所以你可以从 var 中选择它作为字符
foreach ($datanomor as $row){
$var=$row->MaxCode;
//select the first char and casting it to integer then increment it
$var[0] = (int)$var[0]++;
echo $var;
}
推荐阅读
- azure - 如何获取 azure function app 的所有 IP 地址以将它们列入白名单?
- linux - 尝试在bash中使用嵌套的while循环以升序打印数字
- javascript - 如何根据特定值删除数组?
- typescript - 通过省略属性继承打字稿中的类
- node.js - 反应本机 package-lock.json 重复依赖项/包
- python - 一个程序中的名称错误,而另一个程序中的语法错误
- postgresql - 在 Digital Ocean 托管的 kubernetes 集群中配置 Crunchy Data PostgreSQL 操作符
- java - 是继承导致我的编译错误吗?
- python - 为什么这不发送回车键?[Python]
- python - OSError: [WinError 10022] 在 socket.listen(2) 中提供了一个无效参数