Robin S Posted March 12, 2016 Share Posted March 12, 2016 Which of the following is the better way to test if a PageArray contains a particular id? $my_page_array->has("id=1234") or $my_page_array = 1234 Does one perform better than the other? Link to comment Share on other sites More sharing options...
gebeer Posted March 12, 2016 Share Posted March 12, 2016 $my_page_array = 1234 Don't know about performance, but with this code you would set the value of $my_page_array to 1234 which most likely would throw an error. For comparison use $my_page_array === 1234 If you have the $page object that you are searching for already, you can also pass that directly into the has() method like $my_page_array->has($page) instead of $my_page_array->has("id=1234") 5 Link to comment Share on other sites More sharing options...
Robin S Posted March 12, 2016 Author Share Posted March 12, 2016 Don't know about performance, but with this code you would set the value of $my_page_array to 1234 which most likely would throw an error. You are right of course, don't know what I was thinking there... So I think we can safely say that of the two, ->has() definitely performs better Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now