Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
flexslider
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hebotek
flexslider
Commits
f263d847
Commit
f263d847
authored
Aug 21, 2012
by
Andy Hausmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented new Utility method for combining arrays.
parent
9bc346cb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
0 deletions
+43
-0
Div.php
Classes/Utility/Div.php
+43
-0
No files found.
Classes/Utility/Div.php
View file @
f263d847
...
@@ -34,6 +34,49 @@
...
@@ -34,6 +34,49 @@
class
Tx_Flexslider_Utility_Div
class
Tx_Flexslider_Utility_Div
{
{
/**
* Better implementation of php's array_combine().
* This wont throw false in case both array haven't an identical size.
*
* @static
* @param array $a Array containing the keys.
* @param array $b Array containing the values.
* @param bool $pad Switch for allowing padding. Fills the combined array with empty values if any array is larger than the other one.
* @return array Combined array.
*/
public
static
function
combineArray
(
$a
,
$b
,
$pad
=
true
)
{
$acount
=
count
(
$a
);
$bcount
=
count
(
$b
);
// more elements in $a than $b but we don't want to pad either
if
(
!
$pad
)
{
$size
=
(
$acount
>
$bcount
)
?
$bcount
:
$acount
;
$a
=
array_slice
(
$a
,
0
,
$size
);
$b
=
array_slice
(
$b
,
0
,
$size
);
}
else
{
// more headers than row fields
if
(
$acount
>
$bcount
)
{
$more
=
$acount
-
$bcount
;
// how many fields are we missing at the end of the second array?
// Add empty strings to ensure arrays $a and $b have same number of elements
$more
=
$acount
-
$bcount
;
for
(
$i
=
0
;
$i
<
$more
;
$i
++
)
{
$b
[]
=
""
;
}
// more fields than headers
}
else
if
(
$acount
<
$bcount
)
{
$more
=
$bcount
-
$acount
;
// fewer elements in the first array, add extra keys
for
(
$i
=
0
;
$i
<
$more
;
$i
++
)
{
$key
=
'extra_field_0'
.
$i
;
$a
[]
=
$key
;
}
}
}
return
array_combine
(
$a
,
$b
);
}
/**
/**
* Returns the reference to a 'resource' in TypoScript.
* Returns the reference to a 'resource' in TypoScript.
*
*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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