本文介紹了我如何在 php 中將字符串駝峰化的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
有沒有一種簡單的方法可以讓 php camelcase 成為我的字符串?我正在使用 Laravel 框架,我想在搜索功能中使用一些速記.
Is there a simple way I can have php camelcase a string for me? I am using the Laravel framework and I want to use some shorthand in a search feature.
它看起來像下面這樣...
It would look something like the following...
private function search(Array $for, Model $in){
$results = [];
foreach($for as $column => $value){
$results[] = $in->{$this->camelCase($column)}($value)->get();
}
return $results;
}
喜歡
$this->search(['where-created_at' => '2015-25-12'], new Ticket);
所以我將使用的搜索函數中的結果調用是
So the resulting call in the search function I would be using is
$in->whereCreateAt('2015-25-12')->get();
唯一我想不通的是駱駝殼...
The only thing is I can't figure out is the camel casing...
推薦答案
你有沒有考慮過使用 Laravel 內置的駝峰式大小寫功能?
Have you considered using Laravel's built-in camel case functtion?
$camel = camel_case('foo_bar');
可以在此處找到完整的詳細信息:
Full details can be found here:
https://laravel.com/docs/4.2/helpers#strings
這篇關于我如何在 php 中將字符串駝峰化的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!