News Feed
Sections




News Archive
feed this:

Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Theo Kouzelis:
Improving Readability of PHPUnit Data Providers
April 10, 2015 @ 12:01:28

Theo Kouzelis has a recent tutorial posted showing you how to make your PHPUnit tests a bit cleaner with the help of data providers, a built-in tool for PHPUnit that allows for easier validation of larger datasets.

When writing tests I try to describe the test in the function name. I use the format testDoesSomethingWhenPassedSomething to first describe the assertion and then the context. [...] When I have many data sets running against the same test I will use the frameworks data providers to make the code less verbose.

He includes code examples to show both the difference between the single data tests and one using a set of email addresses to validate their correctness. He notes that the error message using data providers can be confusing (and maybe hide the real problem) so he offers a solution to make it more readable: associative arrays. The trick is that PHPUnit uses the key to display the error and by making this unique you can make the error output more informative.

0 comments voice your opinion now!
dataprovider tutorial readability phpunit unittest associative array

Link: http://theo.codes/php/improving-readability-of-phpunit-data-providers.html

PHPBuilder.com:
10 PHP Tricks for Associative Array Manipulation
December 13, 2010 @ 11:54:34

On PHPBuilder.com there's a new tutorial with ten handy tips you can use to work with associative arrays in your PHP applications.

The associative array -- an indispensable data type used to describe a collection of unique keys and associated values -- is a mainstay of all programming languages, PHP included. [...] Such extensive support can be a bit overwhelming to developers seeking the most effective way to manipulate arrays within their applications. In this article, I'll offer 10 tips that can help you shred, slice and dice your data in countless ways.

His tips include working with the arrays by:

  • Adding Array Elements
  • Swapping Keys and Values
  • Editing Array Values
  • Randomizing Array Order
  • Searching the Array
0 comments voice your opinion now!
associative array manipulation tutorial


DevShed:
The Switch Statement and Arrays
January 07, 2008 @ 12:50:00

DevShed continues their series looking at some of the fundamentals of working with PHP in this new tutorial posted today. It looks at one of the flow control statements the language has to offer and a very useful data structure - the switch statement and arrays.

In our last exciting adventure (back in early November), we braved crocodiles, ravenous editors, most of the PHP statements, and beginning loops. In this edition we'll cover the final statement, the Switch, and discuss arrays. So sit back, order your R2D2 robot to bring you a cold, frosty Jolt Cola, and let's get cracking.

They start with a simple example of a switch statement (to echo out strings) and follow it with a detailed description of the different sorts of arrays - numeric indexed, associative and multidimensional versions.

1 comment voice your opinion now!
tutorial switch flow control array numeric associative multidimensional tutorial switch flow control array numeric associative multidimensional


DevShed:
The Basics of Using the Factory Pattern in PHP 5
June 26, 2007 @ 11:07:00

DevShed revisits its series on using design patterns in PHP applications with this new tutorial, a look at implementing the Factory pattern in PHP 5.

Summarizing, the factory pattern can be really useful when it comes to creating multiple objects that belong to the same family. In this three-part series I'm going to take a close look at it, and also demonstrate its remarkable functionality by showing you a decent variety of code samples, so you can start quickly including this pattern into your own PHP applications.

They lay the foundation by creating some basic factory classes for working with numeric and associative arrays. On top of this, they create the processing classes to create things like uppercase numeric arrays and lowercase associative arrays. Finally, they give examples of how to put it to use making several different sorts of arrays, including their output.

0 comments voice your opinion now!
factory designpattern php5 tutorial array associative numeric factory designpattern php5 tutorial array associative numeric


PHPit.net:
Back to basics - PHP & Arrays
January 11, 2006 @ 06:55:49

PHPit.net goes "back to the basics" today with this new post - a look at the basics of how PHP handles arrays and how to use them effectively.

Lately the internet has been on a real fast track, and there have been many new developments, like Ajax, Web 2.0, Tags, and other interesting (and often hyped up) things. But this tutorial won't go there at all, and goes back to the beginning with the basics: using arrays in PHP.

If you're a seasoned PHP developer, who knows arrays like the back of his hand, this might be an article you'd want to skip. But if you're still unsure how arrays work, or if you're just curious about a few things, read on and learn more about arrays in PHP.

This is a very basic article, and doesn't give much in the way of any "array tricks" either. Array functions aren't even covered (mostly) - just how to create and update arrays in your code. But for a beginner, that's all you need...

0 comments voice your opinion now!
arrays back to basics create update associative arrays back to basics create update associative



Community Events

Don't see your event here?
Let us know!


framework extension laravel5 interview podcast laravel php7 introduction install library community opinion example xdebug series language api unittest voicesoftheelephpant release

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework