diff --git a/Curl.class.php b/Curl.class.php index 3508454..1e2c0fe 100644 --- a/Curl.class.php +++ b/Curl.class.php @@ -168,6 +168,10 @@ class Curl { public $response = NULL; } +function is_array_assoc($array) { + return (bool)count(array_filter(array_keys($array), 'is_string')); +} + function is_array_multidim($array) { if (!is_array($array)) { return FALSE; diff --git a/tests/run.php b/tests/run.php index 448cc49..d7288fb 100644 --- a/tests/run.php +++ b/tests/run.php @@ -10,6 +10,22 @@ class CurlTest extends PHPUnit_Framework_TestCase { $this->assertTrue(extension_loaded('curl')); } + public function testArrayAssociative() { + $this->assertTrue(is_array_assoc(array( + 'foo' => 'wibble', + 'bar' => 'wubble', + 'baz' => 'wobble', + ))); + } + + public function testArrayIndexed() { + $this->assertFalse(is_array_assoc(array( + 'wibble', + 'wubble', + 'wobble', + ))); + } + public function testUserAgent() { $test = new Test(); $test->curl->setUserAgent(Curl::USER_AGENT);