Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
typo3
qfq
Commits
f41c915b
Commit
f41c915b
authored
Jan 12, 2016
by
Carsten Rose
Browse files
OnArray.php: Klasse FromArray wurde umbenannt zu OnArray. Neue Funktion sortKey() hinzugefuegt.
parent
24ff6f6e
Changes
2
Hide whitespace changes
Inline
Side-by-side
qfq/helper/OnArray.php
0 → 100644
View file @
f41c915b
<?php
/**
* Created by PhpStorm.
* User: crose
* Date: 1/10/16
* Time: 11:47 AM
*/
namespace
qfq\helper
;
require_once
(
__DIR__
.
'/../../qfq/Constants.php'
);
class
OnArray
{
/**
* @param array $dataArray
* @param string $keyValueGlue
* @param string $rowGlue
* @return string
*/
public
static
function
toString
(
array
$dataArray
,
$keyValueGlue
=
'='
,
$rowGlue
=
'&'
)
{
$dataString
=
''
;
foreach
(
$dataArray
as
$key
=>
$value
)
{
$dataString
.
=
$key
.
$keyValueGlue
.
$value
.
$rowGlue
;
}
$glueLength
=
strlen
(
$rowGlue
);
return
substr
(
$dataString
,
0
,
strlen
(
$dataString
)
-
$glueLength
);
}
/**
* Sort array by array keys
*
* @param array $a
*/
public
static
function
sortKey
(
array
&
$a
)
{
$result
=
array
();
$keys
=
array_keys
(
$a
);
sort
(
$keys
);
foreach
(
$keys
as
$key
)
{
$result
[
$key
]
=
$a
[
$key
];
}
$a
=
$result
;
return
;
}
}
\ No newline at end of file
tests/phpunit/OnArrayTest.php
0 → 100644
View file @
f41c915b
<?php
/**
* Created by PhpStorm.
* User: crose
* Date: 1/12/16
* Time: 9:28 AM
*/
namespace
qfq\helper
;
require_once
(
__DIR__
.
'/../../qfq/helper/OnArray.php'
);
class
OnArrayTest
extends
\
PHPUnit_Framework_TestCase
{
public
function
testSortByKey
()
{
$unsorted
=
[
'a'
=>
'z'
,
'1'
=>
'y'
,
'Aa'
=>
'y0'
,
'zZ'
=>
'X9'
,
'0000'
=>
'h'
];
$sorted
=
[
'0000'
=>
'h'
,
'1'
=>
'y'
,
'Aa'
=>
'y0'
,
'a'
=>
'z'
,
'zZ'
=>
'X9'
];
$expected
=
$unsorted
;
\
qfq\helper\OnArray
::
sortKey
(
$expected
);
$this
->
assertEquals
(
$sorted
,
$expected
);
$expected
=
array
();
\
qfq\helper\OnArray
::
sortKey
(
$expected
);
$this
->
assertEquals
(
array
(),
$expected
);
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment