Articles Tagged 'Array'


Sort an array of arrays in PHP

vista in WordPress: ordinare una serie di post per un campo qualsiasi può essere utilizzata facilmente anche per ordinare array di array . PHP function usort ( ) seen in Wordpress: order a series of posts for any field can be used to easily sort arrays of arrays. For example if we have:

1
2
3
4
5
6
7
8
9
array ( $ Args = array (
'nome' => 'mike' , 'anno' => 2001 ) , array ('name' => 'Mike', 'year' => 2001),
'nome' => 'frank' , 'anno' => 2010 ) , array ('name' => 'Frank', 'year' => 2010),
...
);

$args , function ( $a , $b ) { usort ($ args, function ($ a, $ b) {
$a [ 'anno' ] > $b [ 'anno' ] ) ; return ($ a ['year']> $ b ['year']);
});

Continued ...

Objective-C: how best to use the property list files

One of the advantages of the Property list files, which are simply text files that follow the XML standard, is that you can instantly be transformed into objects (such as array or dictionary) Objective-C. When you create a file list Property:

Property List

Continued ...

Very short snippet: a series of images stored in NSUserDefaults

ai dati dell'immagine. To store an image in NSUserDefaults is sufficient to be able to get a pointer NSData image data. In this way we could rebuild our image at any time thereafter.

In the example shown below is used an array that contains a maximum of 4 images. Each new image is put on the head and the excess removed.

Continued ...

How to develop in PHP with Xcode and Objective-C

How many programmers to use, I also build my own library of functions ready to be reused in multiple projects and multiple contexts. Let me change the title of this post, maybe a little 'risky but, nevertheless, as we shall see, not far from reality.

In Objective-C you can write and call C / C + +, including the assembly for that matter. This characteristic makes it a very versatile language and, in some respects, phenomenal. On the one hand, you can use and appreciate the purely syntax of Objective-C, on the other you can run faster porting code written in ANSI C (perhaps for Digital Unix or Sun) and can comfortably fit into our iPhone or iPad applications; not to mention all the BSD kernel is already available on Mac OS X!

Continued ...

WordPress MU: aggregate individual blogs Tag cloud

It could never happen have to aggregate the individual tag cloud by WordPress MU. In addition, in certain contexts, it may not make sense to show a "cloud" with the tag blog heterogeneous. However, in the unlikely event that someone was for, so here is a simple way to show a tag cloud aggregate.

Continued ...

Very short snippet: Actionscript extend an array by the method shuffle ()

I had already talked about how to implement the method shuffle () in Javascript and Actionscript . I realized, tuttaavia, not pointing out that it is able to extend Actionscript, Javascript in the same way, its object Array :

Continued ...

Very short snippet: shuffle () in Javascript and Actionscript

In PHP there is a handy feature called shuffle() that allows you to mix an array (see Very short trick: take random elements from an array in PHP ). An excellent version of the javascript I found here . Slightly revised the code below:

Continued ...

Very short trick: take random elements from an array in PHP

The function shuffle() PHP "mixes" literally the elements of an array:

1
2
3
4
array ( "ele1" , "ele2" , "ele3" , "ele4" ) ; $ A = array ("ele1", "ele2", "ele3", "ele4");
$a ) ; print_r ($ a);
$a ) ; shuffle ($ a);
$a ) ; print_r ($ a);

Continued ...

WordPress: wp_parse_args ()

The function wp_parse_args() (like many other undocumented) issue a string in the format:

1
var1 = value1 & var2 = value2 ... Varn = valueN

Continued ...

Variety of coding and coding

Some argue that programming is an art and, ultimately, I can only agree especially when it came across very different solutions for the same problem. To understand how true this is how an identical need in medisimo language (JavaScript) can be solved by completely different approaches and original.

Left zero pad

. A number, but the discussion is also valid for any string, such as 123 can be filled on the left - to tie - with a number of zeros, eg 00123 . This need has on several occasions and is useful to put in a column - or at least show - a number in a clean way, implicitly indicating its maximum value. . In the game, for example, the classical score (the score) is often referred to 001234 , indicating that at most we will arrive at 999999 . Here's how the same problem has been solved by various developers:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/ **
* Left Pad String
*
* @ From http://snipplr.com/view/8423/left-pad-string/
* @ Author web-http://www.mechanicmatt.com/
*
* @ Param num - Striga to fill
* @ Param totalChars - Total number of characters, including the "zeros"
* @ Param padWidth - Character used to fill, default "0"
* /
num , totalChars , padWith ) { leadingZeros function (num, totalChars, padWith) {
"" ; num = num + "";
padWith ) ? padWith : "0" ; padWith = (padWith)? padWith: "0";
num. length < totalChars ) { if (no. length <totalChars) {
num. length < totalChars ) { while (no. length <totalChars) {
num ; num = num + padWith;
}
{ } Else {}}

num. length > totalChars ) { //if padWith was a multiple character string and num was overpadded if (no. length> totalChars) {/ / if padWith was multiple character string and num was overpadded
( ( num. length - totalChars ) , totalChars ) ; num = num. substring ((no. length - totalChars), totalChars);
{ } Else {}}

return num;
}
leadingZeros ( "asdf" , 10 , "0" ) ) ; alert (leadingZeros ("asdf", 10, "0"));

scegliendo anche il tipo di carattere da usare tramite padWidth , invece del default 0 . This solution is extremely articulate, yet allows you to add any number of 0 to the number num choosing the type of font used by padWidth , instead of the default 0 .
Very original, however, this solution:

1
2
3
4
5
6
7
8
9
10
11
12
13
/ **
* String_pad
*
* @ From http://snipplr.com/view/700/stringpad/
* @ Author http://d.hatena.ne.jp/brazil/20060721/1153489937
*
* @ Param str - Striga to fill
* @ Param len - Number of characters, including the "zeros"
* @ Param ch - character used to fill
* /
str , len , ch ) { return new Array ( len - ( '' + str ) . length + 1 ) . join ( ch ) + str } function pad (str, len, ch) {return new Array (len - (''+ str). length + 1). join (ch) + str}

pad ( 56 , 4 , '0' ) ) ; // 0056 alert (pad (56, 4, '0 ')) / / 0056

Same result, with a completely different approach. . Again we have the opportunity to decide the number of padding characters using the parameter len and type of font to use with ch . Missing is the use of default provided in the above function.
The one I use, but ...:

1
2
3
4
5
6
7
8
9
10
11
12
/ **
* String_pad
*
* @ Author Giovambattista Fazioli
* @ Web http://www.undolog.com
*
* @ Param s - Striga to fill
* @ Param s - the character string that indicates is that the length
* Such as "0000" = "0" character length 4
* /
s , l ) { return ( l. substr ( 0 , ( l. length - s. length ) ) + s ) ; } padding function (s, l) {return (l substr (0, (l length - length s)) + s);}
padding ( '123' , '0000' ) ) ; alert (padding ('123 ', '0000'));

If you have other interesting solutions do not hesitate to comment : D

Continued ...