php - 怎样拼凑更易读的字符串?
PHPz
PHPz 2017-04-10 15:34:54
[PHP讨论组]
$username = $this->username ?: 'someone';
$email = $this->email ?: Yii::$app->params['adminEmail'];
$password = Yii::$app->getSecurity()->generatePasswordHash(
    $this->password ?: 'xx'
);

$table = User::tableName();
$auth_key = Yii::$app->security->generateRandomString();
$status = User::STATUS_ACTIVE;
$timestamp = time();
$god = 1;

$words  = "in the ${table} has a record which contains some value : ";
$words .= "'${username}', '${email}', '${password}', '${auth_key}', '${status}','${timestamp}', '${god}', '${timestamp}', '${god}' ";

上面的 word 怎样拼凑才能优雅些?

PHPz
PHPz

学习是最好的投资!

全部回复(2)
巴扎黑

sprintf是个不错的方案

不过看你的代码感觉就是像把各种变量都打出来调试用,那么有个神器 get_defined_vars,变量名变量值都有了你值得拥有

PHPz

存数组遍历呗

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号