gpt4 book ai didi

php - MYSQL 选择逗号后的值

转载 作者:行者123 更新时间:2023-11-29 11:29:49 26 4
gpt4 key购买 nike

对 mysql 很陌生,我有一个文本列。值有两种可能的输入场景:

TIME
hour, second

NAME
second

如何检查该值是否具有第一种格式(小时和秒均以逗号分隔),如果是,则仅选择“第二”?

最佳答案

//Assume that you have two formats only for your input like :

$input = '6, 30';

//or

$input = '30';

//Maybe you can try to explode your input into array first with comma :

$input_array = explode(",",$input);

//Then you check whether there is second value in your array or not, if yes then take the second value, else take the first one:

$value = count($input_array) > 1 ? $input_array[1] : $input_array[0];

//Here you will always get the right value :

echo $value;

关于php - MYSQL 选择逗号后的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37605236/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com