Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It depends on the implementation of map::addMarkerByCoords()</p> <p>The method (not a function) name, and its signature, suggests that you are only able to add one coord at a time. But to be sure you'ld need to know the methods true signature. So the question is: does the method allow arrays as arguments?</p> <p>Usually, a method that allows you to add multiple items at once, has the plural name of the intended action in it's name:</p> <p>map::addMarkersByCoords() // note the s after Marker</p> <p>If the 'map' class is your own implementation, you are free to implement it the way you like of course, but in that case keep the descriptive names of the methods in mind. So, add one marker:</p> <p>map::addMarkerByCoords()</p> <p>Add multiple markers at once:</p> <p>map::addMarkersByCoords()</p> <p>Typically you would implement the plural method as something like this:</p> <pre><code>public function addMarkersByCoords( array $markers ) { foreach( $markers as $marker ) { $this-&gt;addMarkerByCoord( $marker[ 'long' ], $marker[ 'lat' ], $marker[ 'img ' ], $marker[ 'name' ] ); } } </code></pre> <p>Basically, the plural method accepts one array, and adds each individual marker by calling the singular method.</p> <p>If you wanna get even more OOP, you could implement the plural and singular method to accept (an array of) Marker objects. But that is not particalarly relevant for this discussion.</p> <p>Also, the suggested expantion of the Map's interface with a plural method doesn't nessecarily mean you can't add multiple markers outside the object with calling the singular method in a foreach loop. It's up to your preference really.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload