I have a class that is containing 10 methods. I always need to use one of those methods. Now I want to know, which approach is better? OR Answer It is an interesting subject. I’m gonna give you a design oriented answer. In my opinion, you should never use a static class/function in a good OOP architectu…
Tag: php
DateTime with microseconds
In my code, I’m using DateTime objects to manipulate dates, then convert them to timestamp in order to save them in some JSON files. For some reasons, I want to have the same thing as DateTime (or something close), but with microseconds precision (that I would convert to float when inserting inside the …
Check if one of multiple words exists in the string?
I have a string like this: I want to check it for these words: it, test. I want to it returns true if there is at least one of those words in the string. Here is what I did: (though it does not work) How can I do that? Answer Simply checking using preg_match(), you can add many different words
Laravel blade “old input or default variable”?
I want to show the old input in input value. If there isn’t old input, than show other variable: But when there is no old input, it gives me 1 instead of the default value! I think the problem has something to do with the concatenation, but I don’t know how to fix it!? Answer or is a comparison op…
Clone entity and all related entities in CakePHP 3
In my CakePHP 3 app, I have a somewhat elaborate tree of entities that I need to clone and save. The root of the structure is a Questionnaire, a Questionnaire hasMany Questions, each Question hasMany Fields, etc. (it goes deeper). Now I want the user to be able to define a new questionnaire by copying an old …
Nullable return types in PHP7
PHP 7 introduces return type declarations. Which means I can now indicate the return value is a certain class, interface, array, callable or one of the newly hintable scalar types, as is possible for …
Default Filter in GridView with Yii2
I don’t know how to set the filter default of GridView. It’s mean when page loaded, it’s will load the filter with specific condition that I’ve set. Any idea for this? Thanks
How to print out value on controller Laravel?
I’m beginner on Laravel… How to debug some value on controller in Laravel, result can show to console like syntax console.log() on javascript? example controller function : Answer In Laravel use dd($id) or if you don’t want to halt the execution, you can use dump($var). You can still always …
Update table structure without rollback in Laravel 5.1
I am beginner in Laravel. I use migrate to create tables in a database, but I don’t want to migrate:rollback to update my table. I want to apply changes in my old database without loosing current …
Loop through associative array of associative arrays using foreach loop [closed]
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 7 years ago. Improve this question how can i loop through this php associative array using foreach loop?? Ans…