Git Product home page Git Product logo

Comments (7)

samdark avatar samdark commented on June 25, 2024

That's simple enough check not to have a special wrapper for it:

if (\trim($string) === '') {

from yii-core.

GHopperMSK avatar GHopperMSK commented on June 25, 2024

That's simple enough check not to have a special wrapper for it:

if (\trim($string) === '') {

What about null? What about type casting (int, obj)? I use such function all the time and think it is quite useful.

from yii-core.

GHopperMSK avatar GHopperMSK commented on June 25, 2024

Wow...
It may be useful to know that trim() returns an empty string when the argument is an unset/null variable.
I didn't know that! You are right, isEmpty now useless.

from yii-core.

GHopperMSK avatar GHopperMSK commented on June 25, 2024

And one more question - I used to use helper ArrayHelper::isSet($array, $path) which takes an array and a key path and check if the path exists.

isSet([
  [
    'one' => 'One',
    'two' => [
        'label' => 'Two',
        'value' => 2
    ],
  ],
], 
'0.two.label') // true

Can I do the same by native php function?

from yii-core.

samdark avatar samdark commented on June 25, 2024

No, that you cannot do with native function.

from yii-core.

mozarcik avatar mozarcik commented on June 25, 2024

Actually he can do this

isset($arr[0]['two']['label'])

It checks for all keys and when any defined does not exist it returns false, I don't see a reason to use dot syntax here

from yii-core.

tomaszkane avatar tomaszkane commented on June 25, 2024

BTW, I like null operator on similar case:
return $array['foo']['boo'] ?? false;

from yii-core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.